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

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions lib/matplotlib/cbook/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1389,9 +1389,13 @@ def _reshape_2D(X, name):
for xi in X:
# check if this is iterable, except for strings which we
# treat as singletons.
if (isinstance(xi, collections.abc.Iterable) and
not isinstance(xi, str)):
is_1d = False
if not isinstance(xi, str):
try:
iter(xi)
except TypeError:
pass
else:
is_1d = False
xi = np.asanyarray(xi)
nd = np.ndim(xi)
if nd > 1:
Expand Down
7 changes: 7 additions & 0 deletions lib/matplotlib/tests/test_cbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,13 @@ class Dummy:
assert isinstance(xnew[1], np.ndarray) and xnew[1].shape == (1,)
assert isinstance(xnew[2], np.ndarray) and xnew[2].shape == (1,)

# Test a list of zero-dimensional arrays
x = [np.array(0), np.array(1), np.array(2)]
xnew = cbook._reshape_2D(x, 'x')
assert isinstance(xnew, list)
assert len(xnew) == 1
assert isinstance(xnew[0], np.ndarray) and xnew[0].shape == (3,)

# Now test with a list of lists with different lengths, which means the
# array will internally be converted to a 1D object array of lists
x = [[1, 2, 3], [3, 4], [2]]
Expand Down