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

Skip to content

Commit be849c5

Browse files
committed
Fix evaluating colormaps on non-numpy arrays
Closes #23132. I can't specifically test that case, because we don't have pytorch as a test dependency. However, I'd claim that deferring np.nan() to after converting to a numpy array is obviously the right thing to do.
1 parent cada8fb commit be849c5

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)