Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IndexError: tuple index out of range with pandas 0.25. #14992

Closed
Foadsf opened this issue Aug 6, 2019 · 15 comments · Fixed by #15007
Closed

IndexError: tuple index out of range with pandas 0.25. #14992

Foadsf opened this issue Aug 6, 2019 · 15 comments · Fixed by #15007
Labels
Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. status: upstream fix required third-party integration
Milestone

Comments

@Foadsf
Copy link

Foadsf commented Aug 6, 2019

Bug report

Bug summary

I have reported the issue in details here
basically after an upgrade to 3.1.1 it drops the error:

IndexError: tuple index out of range

all other details inclduing the CSV file and code are in the above link.

@jamespreed
Copy link

Looks like this commit changed how the indices were assigned by removing the _xy_from_xy method. This works as of 3.1.0, but not 3.1.1 (on Windows).

@Foadsf
Copy link
Author

Foadsf commented Aug 6, 2019

Downgrading to the previous versions doesn't help! There might be more issues IMHO ¯\_(ツ)_/¯

@anntzer
Copy link
Contributor

anntzer commented Aug 6, 2019

This is actually due to the upgrade to pandas 0.25:

import pandas as pd
df = pd.DataFrame({"a": [1, 2, 3]})
print(df.index.shape, df.index[:, None].shape)

This now prints (3,) (3,), but with pandas 0.24 used to print (3,) (3, 1) which we relied on to convert input to 2D.

@Foadsf
Copy link
Author

Foadsf commented Aug 6, 2019

@anntzer downgrading to Pandas 0.24 solved the problem!

@Foadsf
Copy link
Author

Foadsf commented Aug 6, 2019

I reported an issue on pandas repo here

@anntzer anntzer changed the title IndexError: tuple index out of range after upgrade to 3.1.1 IndexError: tuple index out of range with pandas 0.25. Aug 6, 2019
@jorisvandenbossche
Copy link

@story645 I am not fully sure we can provide an upstream fix (or at least not long term).

df.index is a one-dimensional object, so df.index[:, None] actually giving an Index that is 2D, could have been considered a bug in pandas.

@tacaswell
Copy link
Member

@Foadsf Can you please paste a minimal copy-pastable example into this issue? SO links rot over time.

@story645
Copy link
Member

story645 commented Aug 6, 2019

@jorisvandenbossche wondering then if pandas should be throwing a warning or something since
array[:,None] syntax is the numpy recommended way of expanding dims and so the expectation there is to return a 2D item.

@jklymak
Copy link
Member

jklymak commented Aug 7, 2019

What does np.newaxis give if we use that instead?

@Foadsf
Copy link
Author

Foadsf commented Aug 7, 2019

Dear @tacaswell the Pandas guys were kind to edit my post here and add clear and concise examples demonstrating the issue.

@jorisvandenbossche
Copy link

@Foadsf that's a reproducible example for just the pandas side, but I think @tacaswell is looking for an example that shows the error with matplotlib.

Something like

s = pd.Series([1, 2, 3])
plt.plot(s.index, s.values)

@tacaswell
Copy link
Member

Thanks @jorisvandenbossche

@Foadsf in general, you will get much better responses from projects if you provide an easily understandable and testable examples (see http://www.sscce.org/ for a longer discussion as to why). The information we ask for in the issue template to guide you so we can help you as easily as possible.

@QuLogic
Copy link
Member

QuLogic commented Aug 7, 2019

@jklymak np.newaxis is None; there is no difference between the two other than programmer clarity.

@ImportanceOfBeingErnest
Copy link
Member

df = pd.DataFrame({"XX" : [4,5,6], "YY" : [7,1,2]})
print(df.index[:,None].shape)
print(df["YY"][:,None].shape)

prints

(3,)
(3, 1)

This seems rather inconsistent.

Marking as release critical, because something needs to be done here.

@ImportanceOfBeingErnest ImportanceOfBeingErnest added this to the v3.2.0 milestone Aug 7, 2019
@ImportanceOfBeingErnest ImportanceOfBeingErnest added the Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. label Aug 7, 2019
@tacaswell tacaswell modified the milestones: v3.2.0, v2.2.5 Aug 8, 2019
tacaswell added a commit to tacaswell/matplotlib that referenced this issue Aug 8, 2019
@jorisvandenbossche
Copy link

This seems rather inconsistent.

@ImportanceOfBeingErnest yes, that is certainly inconsistent, and "kind of" a regression in pandas (which I also propose to fix in pandas itself for 0.25.1, see pandas-dev/pandas#27775 (comment))
I am saying "kind of" because we should decide what to do when you end up with a 2D Index (which is invalid, but currently you can get that with the indexing operation as idx[:, None]): return a 2D array or raise an error.
series[:, None] does return a 2D numpy array, hence you get the correct shape.

But in any case, I think it would be good for matplotlib to not rely on this indexing aspect to convert a pandas Index into a 2D array-like.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. status: upstream fix required third-party integration
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants