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

Skip to content

Fix empty reshape2d #13402

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 11, 2019
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
2 changes: 2 additions & 0 deletions lib/matplotlib/cbook/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1416,6 +1416,8 @@ def _reshape_2D(X, name):
"""
# Iterate over columns for ndarrays, over rows otherwise.
X = np.atleast_1d(X.T if isinstance(X, np.ndarray) else np.asarray(X))
if len(X) == 0:
return [[]]
if X.ndim == 1 and not isinstance(X[0], collections.abc.Iterable):
# 1D array of scalars: directly return it.
return [X]
Expand Down
4 changes: 4 additions & 0 deletions lib/matplotlib/tests/test_cbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,11 @@ def test_flatiter():
def test_reshape2d():
class dummy():
pass
xnew = cbook._reshape_2D([], 'x')
assert np.shape(xnew) == (1, 0)

x = [dummy() for j in range(5)]

xnew = cbook._reshape_2D(x, 'x')
assert np.shape(xnew) == (1, 5)

Expand Down