Skip to content

Commit 07268f0

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 9bcdd60 commit 07268f0

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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy