IndexError: tuple index out of range after upgrade to 0.25 · Issue #27775 · pandas-dev/pandas (original) (raw)
Root cause (in both cases using df = pd.DataFrame({'a': [1, 2, 3]})
):
In [71]: pd.__version__
Out[71]: '0.25.0'
In [73]: df.index[:, None]
Out[73]: Int64Index([0, 1, 2], dtype='int64')
In [74]: df.index[:, None].shape
Out[74]: (3,)
vs
In [10]: pd.__version__
Out[10]: '0.24.2'
In [13]: df.index[:, None]
Out[13]: Int64Index([0, 1, 2], dtype='int64')
In [14]: df.index[:, None].shape
Out[14]: (3, 1)
So before, indexing with [:, None]
(in numpy a way to add a dimension to get 2D array) actually resulting in Index with ndim of 2 (but which is of course inconsistent state of the Index object)
Matplotlib relied on this fact when an Index is passed to plt.plot
, as reported in matplotlib/matplotlib#14992
I have explained the issue here and here in details. Basically, after upgrading to the version 0.25
I got the error:
IndexError: tuple index out of range
while attempting to plot a CSV file.