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

Skip to content

Commit 56755e4

Browse files
authored
Merge pull request #13402 from jklymak/fix-empty-reshape2d
FIX: empty reshape2d
2 parents 5d56c1c + fd04f2d commit 56755e4

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

lib/matplotlib/cbook/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1416,6 +1416,8 @@ def _reshape_2D(X, name):
14161416
"""
14171417
# Iterate over columns for ndarrays, over rows otherwise.
14181418
X = np.atleast_1d(X.T if isinstance(X, np.ndarray) else np.asarray(X))
1419+
if len(X) == 0:
1420+
return [[]]
14191421
if X.ndim == 1 and not isinstance(X[0], collections.abc.Iterable):
14201422
# 1D array of scalars: directly return it.
14211423
return [X]

lib/matplotlib/tests/test_cbook.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,11 @@ def test_flatiter():
495495
def test_reshape2d():
496496
class dummy():
497497
pass
498+
xnew = cbook._reshape_2D([], 'x')
499+
assert np.shape(xnew) == (1, 0)
500+
498501
x = [dummy() for j in range(5)]
502+
499503
xnew = cbook._reshape_2D(x, 'x')
500504
assert np.shape(xnew) == (1, 5)
501505

0 commit comments

Comments
 (0)