Indexing Regression in 0.13.0 · Issue #6394 · pandas-dev/pandas (original) (raw)
In pandas 0.12 the order you indexed a DataFrame didn't matter, which I think is the correct behaviour:
In [6]: df = pd.DataFrame({'A': 5*[np.zeros(3)], 'B':5*[np.ones(3)]})
In [7]: df Out[7]:
A B
0 [0.0, 0.0, 0.0] [1.0, 1.0, 1.0] 1 [0.0, 0.0, 0.0] [1.0, 1.0, 1.0] 2 [0.0, 0.0, 0.0] [1.0, 1.0, 1.0] 3 [0.0, 0.0, 0.0] [1.0, 1.0, 1.0] 4 [0.0, 0.0, 0.0] [1.0, 1.0, 1.0]
In [8]: df['A'].iloc[2] Out[8]: array([ 0., 0., 0.])
In [9]: df.iloc[2]['A'] Out[9]: array([ 0., 0., 0.])
In [10]: pd.version Out[10]: '0.12.0'
In [11]: assert type(df.ix[2, 'A']) == type(df['A'].iloc[2]) == type(df.iloc[2]['A'])
In [12]:
In pandas 0.13 if you index in a different order you can get a different type out which can be problematic for code expecting an array, especially because of the difference between array indexing and label indexing.
In [1]: df = pd.DataFrame({'A': 5*[np.zeros(3)], 'B':5*[np.ones(3)]})
In [2]: df Out[2]:
A B
0 [0.0, 0.0, 0.0] [1.0, 1.0, 1.0] 1 [0.0, 0.0, 0.0] [1.0, 1.0, 1.0] 2 [0.0, 0.0, 0.0] [1.0, 1.0, 1.0] 3 [0.0, 0.0, 0.0] [1.0, 1.0, 1.0] 4 [0.0, 0.0, 0.0] [1.0, 1.0, 1.0] 5 rows × 2 columns
In [3]: df['A'].iloc[2] Out[3]: array([ 0., 0., 0.])
In [4]: df.iloc[2]['A'] Out[4]: A 0 A 0 A 0 Name: 2, dtype: float64
In [5]: pd.version Out[5]: '0.13.1'
In [6]: assert type(df.ix[2, 'A']) == type(df['A'].iloc[2]) == type(df.iloc[2]['A']) Traceback (most recent call last):
File "", line 1, in assert type(df.ix[2, 'A']) == type(df['A'].iloc[2]) == type(df.iloc[2]['A'])
AssertionError