Skip to content

Commit ae4354c

Browse 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 ae4354c

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

lib/matplotlib/cbook/__init__.py

Lines 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() as w:
1377+
warnings.filterwarnings("ignore",
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

0 commit comments

Comments
 (0)