-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
FIX: support pandas 0.25 #15007
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
FIX: support pandas 0.25 #15007
Conversation
lib/matplotlib/cbook/__init__.py
Outdated
shape = x[:, None].shape | ||
# work around https://github.com/pandas-dev/pandas/issues/27775 | ||
# which mean the shape is not as expected | ||
if len(shape) != 2: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's x[:, None].ndim
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would rather check the shape as that is what needs to be correct and do not want to risk ndim
also being out of sync.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you think than .ndim may be returning something wrong then .shape could also be wrong, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the pandas issue they pointed out that this changes was due to an optimization (see pandas-dev/pandas#27775 (comment)) on Index
and the current implementation of ndim
is:
@property
def ndim(self):
"""
Number of dimensions of the underlying data, by definition 1.
"""
return 1
https://github.com/pandas-dev/pandas/blob/8b6942f2876264b745529a3c3a7cf410ee096c34/pandas/core/base.py#L694-L699 which confirmed my suspicioun that shape
and ndim
were out of sync.
However, digging through this convinced me that we I should check that x[:, None].ndim >= 2
as this will fail on older version of pandas and stop relying on an unintentional quirk of Index classes almost ducktyping as arrays.
This will fail on older version of pandas as well.
5fb7f5e
to
df4b7dc
Compare
@@ -1326,7 +1326,13 @@ def _check_1d(x): | |||
return np.atleast_1d(x) | |||
else: | |||
try: | |||
x[:, None] | |||
ndim = x[:, None].ndim |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you don't want to do a np.asarray
here first? That should make it work with older pandas versions, but also robust to potential future changes (eg if pandas starts raising for that)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we do not want to asarray
things we don't have to (in particular because in some cases that can strip units off of things). So long as future versions raises one of the two exceptions caught below it will "just work" and as soon as you decide what exception you are going to raise we can add it.
The point of this is to check if we need to asarray
(which in done implicitly in atleast_1d
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I see. I suppose if we raise an error it will be an IndexError, so that would already be covered then
…007-on-v3.1.x Backport PR #15007 on branch v3.1.x (FIX: support pandas 0.25)
…007-on-v2.2.x Backport PR #15007 on branch v2.2.x (FIX: support pandas 0.25)
closes #14992
PR Summary
PR Checklist