-
-
Notifications
You must be signed in to change notification settings - Fork 18.7k
Closed
Milestone
Description
I get a very strange behaviour with pandas current dev version (tagged as '0.9.0rc2') :
Calling set_index() on a DataFrame breaks depending on the columns name I use !!!
This code fails :
df3 = DataFrame({
'0001-INTERNAL_PRODUCT_CODE': {('A', 'A0006000', 'nuit'): 'A0006000'},
'0004-PACKAGING_LANGUAGE_CODE': {('A', 'A0006000', 'nuit'): nan},
'1050-LOCALISED_DESCRIPTION': {('A', 'A0006000', 'nuit'): nan},
'0024-PRODUCT_BAR_CODED': {('A', 'A0006000', 'nuit'): nan},
'Source system': {('A', 'A0006000', 'nuit'): 'A'},
'0027-LOCAL_COMMERCIAL_AUTHORIZATION': {('A', 'A0006000', 'nuit'): nan},
})
df3.set_index(['0001-INTERNAL_PRODUCT_CODE', '1050-LOCALISED_DESCRIPTION']) # fails !
But If I change the indexed column names to 'a' and 'x', It works :
df3 = DataFrame({
'a': {('A', 'A0006000', 'nuit'): 'A0006000'},
'0004-PACKAGING_LANGUAGE_CODE': {('A', 'A0006000', 'nuit'): nan},
'x': {('A', 'A0006000', 'nuit'): nan},
'0024-PRODUCT_BAR_CODED': {('A', 'A0006000', 'nuit'): nan},
'Source system': {('A', 'A0006000', 'nuit'): 'A'},
'0027-LOCAL_COMMERCIAL_AUTHORIZATION': {('A', 'A0006000', 'nuit'): nan},
})
df3.set_index(['a', 'x']) # works !
At first I thought It was related to column name .... but If I keep my exotic column name and remove one column (one not used by set_index), it works !! :
df3 = DataFrame({
'0001-INTERNAL_PRODUCT_CODE': {('A', 'A0006000', 'nuit'): 'A0006000'},
'1050-LOCALISED_DESCRIPTION': {('A', 'A0006000', 'nuit'): nan},
'0024-PRODUCT_BAR_CODED': {('A', 'A0006000', 'nuit'): nan},
'Source system': {('A', 'A0006000', 'nuit'): 'A'},
'0027-LOCAL_COMMERCIAL_AUTHORIZATION': {('A', 'A0006000', 'nuit'): nan},
})
df3.set_index(['0001-INTERNAL_PRODUCT_CODE', '1050-LOCALISED_DESCRIPTION']) # works !