Skip to content

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

Merged
merged 3 commits into from
Aug 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion lib/matplotlib/cbook/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1326,7 +1326,13 @@ def _check_1d(x):
return np.atleast_1d(x)
else:
try:
x[:, None]
ndim = x[:, None].ndim

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)

Copy link
Member Author

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).

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

# work around https://github.com/pandas-dev/pandas/issues/27775
# which mean the shape is not as expected. That this ever worked
# was an unintentional quirk of pandas the above line will raise
# an exception in the future.
if ndim < 2:
return np.atleast_1d(x)
return x
except (IndexError, TypeError):
return np.atleast_1d(x)
Expand Down
6 changes: 6 additions & 0 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -5552,6 +5552,12 @@ def test_pandas_errorbar_indexing(pd):
ax.errorbar('x', 'y', xerr='xe', yerr='ye', data=df)


def test_pandas_index_shape(pd):
df = pd.DataFrame({"XX": [4, 5, 6], "YY": [7, 1, 2]})
fig, ax = plt.subplots()
ax.plot(df.index, df['YY'])


def test_pandas_indexing_hist(pd):
ser_1 = pd.Series(data=[1, 2, 2, 3, 3, 4, 4, 4, 4, 5])
ser_2 = ser_1.iloc[1:]
Expand Down