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

Commit0040b0a

Browse files
authored
Merge pull request#22592 from meeseeksmachine/auto-backport-of-pr-22141-on-v3.5.x
Backport PR#22141 on branch v3.5.x (Fix check 1d)
2 parents17b4e10 +4715aff commit0040b0a

File tree

2 files changed

+14
-44
lines changed

2 files changed

+14
-44
lines changed

‎lib/matplotlib/cbook/__init__.py

Lines changed: 5 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1300,47 +1300,13 @@ def _to_unmasked_float_array(x):
13001300

13011301
def_check_1d(x):
13021302
"""Convert scalars to 1D arrays; pass-through arrays as is."""
1303+
ifhasattr(x,'to_numpy'):
1304+
# if we are given an object that creates a numpy, we should use it...
1305+
x=x.to_numpy()
13031306
ifnothasattr(x,'shape')orlen(x.shape)<1:
13041307
returnnp.atleast_1d(x)
13051308
else:
1306-
try:
1307-
# work around
1308-
# https://github.com/pandas-dev/pandas/issues/27775 which
1309-
# means the shape of multi-dimensional slicing is not as
1310-
# expected. That this ever worked was an unintentional
1311-
# quirk of pandas and will raise an exception in the
1312-
# future. This slicing warns in pandas >= 1.0rc0 via
1313-
# https://github.com/pandas-dev/pandas/pull/30588
1314-
#
1315-
# < 1.0rc0 : x[:, None].ndim == 1, no warning, custom type
1316-
# >= 1.0rc1 : x[:, None].ndim == 2, warns, numpy array
1317-
# future : x[:, None] -> raises
1318-
#
1319-
# This code should correctly identify and coerce to a
1320-
# numpy array all pandas versions.
1321-
withwarnings.catch_warnings(record=True)asw:
1322-
warnings.filterwarnings(
1323-
"always",
1324-
category=Warning,
1325-
message='Support for multi-dimensional indexing')
1326-
1327-
ndim=x[:,None].ndim
1328-
# we have definitely hit a pandas index or series object
1329-
# cast to a numpy array.
1330-
iflen(w)>0:
1331-
returnnp.asanyarray(x)
1332-
# We have likely hit a pandas object, or at least
1333-
# something where 2D slicing does not result in a 2D
1334-
# object.
1335-
ifndim<2:
1336-
returnnp.atleast_1d(x)
1337-
returnx
1338-
# In pandas 1.1.0, multidimensional indexing leads to an
1339-
# AssertionError for some Series objects, but should be
1340-
# IndexError as described in
1341-
# https://github.com/pandas-dev/pandas/issues/35527
1342-
except (AssertionError,IndexError,TypeError):
1343-
returnnp.atleast_1d(x)
1309+
returnx
13441310

13451311

13461312
def_reshape_2D(X,name):
@@ -1649,7 +1615,7 @@ def index_of(y):
16491615
The x and y values to plot.
16501616
"""
16511617
try:
1652-
returny.index.values,y.values
1618+
returny.index.to_numpy(),y.to_numpy()
16531619
exceptAttributeError:
16541620
pass
16551621
try:

‎lib/matplotlib/tests/test_axes.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1762,11 +1762,15 @@ def test_bar_hatches(fig_test, fig_ref):
17621762

17631763
deftest_pandas_minimal_plot(pd):
17641764
# smoke test that series and index objcets do not warn
1765-
x=pd.Series([1,2],dtype="float64")
1766-
plt.plot(x,x)
1767-
plt.plot(x.index,x)
1768-
plt.plot(x)
1769-
plt.plot(x.index)
1765+
forxin [pd.Series([1,2],dtype="float64"),
1766+
pd.Series([1,2],dtype="Float64")]:
1767+
plt.plot(x,x)
1768+
plt.plot(x.index,x)
1769+
plt.plot(x)
1770+
plt.plot(x.index)
1771+
df=pd.DataFrame({'col': [1,2,3]})
1772+
plt.plot(df)
1773+
plt.plot(df,df)
17701774

17711775

17721776
@image_comparison(['hist_log'],remove_text=True)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp