10000 Merge pull request #24009 from timhoffm/fix-pytorch · matplotlib/matplotlib@30fbb45 · GitHub
[go: up one dir, main page]

Skip to content

Commit 30fbb45

Browse files
authored
Merge pull request #24009 from timhoffm/fix-pytorch
Fix evaluating colormaps on non-numpy arrays
2 parents e7f52ea + 07268f0 commit 30fbb45

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

lib/matplotlib/colors.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -706,8 +706,12 @@ def __call__(self, X, alpha=None, bytes=False):
706706
if not self._isinit:
707707
self._init()
708708

709-
mask_bad = X.mask if np.ma.is_masked(X) else np.isnan(X) # Mask nan's.
709+
# Take the bad mask from a masked array, or in all other cases defer
710+
# np.isnan() to after we have converted to an array.
711+
mask_bad = X.mask if np.ma.is_masked(X) else None
710712
xa = np.array(X, copy=True)
713+
if mask_bad is None:
714+
mask_bad = np.isnan(xa)
711715
if not xa.dtype.isnative:
712716
xa = xa.byteswap().newbyteorder() # Native byteorder is faster.
713717
if xa.dtype.kind == "f":

0 commit comments

Comments
 (0)
0