Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5052af5

Browse files
committed
FIX: accomodate pandas type that doesn't return numpy from .values
1 parent 0548b11 commit 5052af5

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

lib/matplotlib/cbook/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1339,7 +1339,8 @@ def _check_1d(x):
13391339
# AssertionError for some Series objects, but should be
13401340
# IndexError as described in
13411341
# https://github.com/pandas-dev/pandas/issues/35527
1342-
except (AssertionError, IndexError, TypeError):
1342+
# ValueError: https://github.com/matplotlib/matplotlib/issues/22125
1343+
except (AssertionError, IndexError, TypeError, ValueError):
13431344
return np.atleast_1d(x)
13441345

13451346

@@ -1649,7 +1650,7 @@ def index_of(y):
16491650
The x and y values to plot.
16501651
"""
16511652
try:
1652-
return y.index.values, y.values
1653+
return y.index.to_numpy(), y.to_numpy()
16531654
except AttributeError:
16541655
pass
16551656
try:

lib/matplotlib/tests/test_axes.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1749,11 +1749,12 @@ def test_bar_hatches(fig_test, fig_ref):
17491749

17501750
def test_pandas_minimal_plot(pd):
17511751
# smoke test that series and index objcets do not warn
1752-
x = pd.Series([1, 2], dtype="float64")
1753-
plt.plot(x, x)
1754-
plt.plot(x.index, x)
1755-
plt.plot(x)
1756-
plt.plot(x.index)
1752+
for x in [pd.Series([1, 2], dtype="float64"),
1753+
pd.Series([1, 2], dtype="Float32")]:
1754+
plt.plot(x, x)
1755+
plt.plot(x.index, x)
1756+
plt.plot(x)
1757+
plt.plot(x.index)
17571758

17581759

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

0 commit comments

Comments
 (0)