Thanks to visit codestin.com Credit goes to github.com
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 682836c commit cf9bb88Copy full SHA for cf9bb88
2 files changed
lib/matplotlib/cbook/__init__.py
@@ -1355,6 +1355,17 @@ def _reshape_2D(X, name):
1355
1356
*name* is used to generate the error message for invalid inputs.
1357
"""
1358
+
1359
+ # unpack if we have a values or to_numpy method.
1360
+ try:
1361
+ X = X.to_numpy()
1362
+ except AttributeError:
1363
1364
+ if isinstance(X.values, np.ndarray):
1365
+ X = X.values
1366
1367
+ pass
1368
1369
# Iterate over columns for ndarrays.
1370
if isinstance(X, np.ndarray):
1371
X = X.T
lib/matplotlib/tests/test_cbook.py
@@ -559,6 +559,23 @@ def __getitem__(self, item):
559
assert isinstance(xnew[0], np.ndarray)
560
561
562
+def test_reshape2d_pandas(pd):
563
+ # seperate to allow the rest of the tests to run if no pandas...
564
+ X = np.arange(30).reshape(10, 3)
565
+ x = pd.DataFrame(X, columns=["a", "b", "c"])
566
+ Xnew = cbook._reshape_2D(x, 'x')
567
+ # Need to check each row because _reshape_2D returns a list of arrays:
568
+ for x, xnew in zip(X.T, Xnew):
569
+ np.testing.assert_array_equal(x, xnew)
570
571
572
573
574
575
576
577
578
579
def test_contiguous_regions():
580
a, b, c = 3, 4, 5
581
# Starts and ends with True
0 commit comments