Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c7eddd6

Browse filesBrowse files
committed
FIX: catch warnings from pandas in cbook._check_1d
If we catch the warning or the exception, we need to cast to numpy because later on in `_plot_args` we again use multi-dimensional indexing to up-cast to a 2D array. closes #16295
1 parent 1ad7eb0 commit c7eddd6
Copy full SHA for c7eddd6

File tree

Expand file treeCollapse file tree

2 files changed

+20
-1
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+20
-1
lines changed

‎lib/matplotlib/cbook/__init__.py

Copy file name to clipboardExpand all lines: lib/matplotlib/cbook/__init__.py
+12-1Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1367,11 +1367,22 @@ def _check_1d(x):
13671367
return np.atleast_1d(x)
13681368
else:
13691369
try:
1370-
ndim = x[:, None].ndim
13711370
# work around https://github.com/pandas-dev/pandas/issues/27775
13721371
# which mean the shape is not as expected. That this ever worked
13731372
# was an unintentional quirk of pandas the above line will raise
13741373
# an exception in the future.
1374+
# This warns in pandas >= 1.0 via
1375+
# https://github.com/pandas-dev/pandas/pull/30588
1376+
with warnings.catch_warnings(record=True) as w:
1377+
warnings.filterwarnings("always",
1378+
category=DeprecationWarning,
1379+
module='pandas[.*]')
1380+
1381+
ndim = x[:, None].ndim
1382+
# we have definitely hit a pandas index or series object
1383+
# cast to a numpy array.
1384+
if len(w) != 0:
1385+
return np.asanyarray(x)
13751386
if ndim < 2:
13761387
return np.atleast_1d(x)
13771388
return x

‎lib/matplotlib/tests/test_axes.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_axes.py
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1695,6 +1695,14 @@ def test_bar_pandas_indexed(pd):
16951695
ax.bar(df.x, 1., width=df.width)
16961696

16971697

1698+
def test_pandas_smoke(pd):
1699+
# This should not raise any warnings
1700+
x = pd.Series([], dtype="float64")
1701+
plt.plot(x, x)
1702+
plt.plot(x.index, x)
1703+
plt.plot(x)
1704+
1705+
16981706
@image_comparison(['hist_log'], remove_text=True)
16991707
def test_hist_log():
17001708
data0 = np.linspace(0, 1, 200)**3

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.