Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commitc7eddd6

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 numpybecause later on in `_plot_args` we again use multi-dimensionalindexing to up-cast to a 2D array.closes#16295
1 parent1ad7eb0 commitc7eddd6

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-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
returnnp.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+
withwarnings.catch_warnings(record=True)asw:
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+
iflen(w)!=0:
1385+
returnnp.asanyarray(x)
13751386
ifndim<2:
13761387
returnnp.atleast_1d(x)
13771388
returnx

‎lib/matplotlib/tests/test_axes.py

Lines 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+
deftest_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
deftest_hist_log():
17001708
data0=np.linspace(0,1,200)**3

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp