@@ -550,46 +550,30 @@ def __call__(self, X, alpha=None, bytes=False):
550
550
-------
551
551
Tuple of RGBA values if X is scalar, otherwise an array of
552
552
RGBA values with a shape of ``X.shape + (4, )``.
553
-
554
553
"""
555
- # See class docstring for arg/kwarg documentation.
556
554
if not self ._isinit :
557
555
self ._init ()
558
- mask_bad = None
559
- if np .ma .is_masked (X ):
560
- mask_bad = X .mask
561
- elif np .any (np .isnan (X )):
562
- # mask nan's
563
- mask_bad = np .isnan (X )
564
556
557
+ mask_bad = X .mask if np .ma .is_masked (X ) else np .isnan (X ) # Mask nan's.
565
558
xa = np .array (X , copy = True )
566
- # Fill bad values to avoid warnings
567
- # in the boolean comparisons below.
568
- if mask_bad is not None :
569
- xa [mask_bad ] = 0.
570
-
571
- # Calculations with native byteorder are faster, and avoid a
572
- # bug that otherwise can occur with putmask when the last
573
- # argument is a numpy scalar.
574
559
if not xa .dtype .isnative :
575
- xa = xa .byteswap ().newbyteorder ()
576
-
560
+ xa = xa .byteswap ().newbyteorder () # Native byteorder is faster.
577
561
if xa .dtype .kind == "f" :
578
- xa *= self .N
579
- # Negative values are out of range, but astype(int) would truncate
580
- # them towards zero.
581
- xa [xa < 0 ] = - 1
582
- # xa == 1 (== N after multiplication) is not out of range.
583
- xa [xa == self .N ] = self .N - 1
584
- # Avoid converting large positive values to negative integers.
585
- np .clip (xa , - 1 , self .N , out = xa )
586
- xa = xa .astype (int )
562
+ with np .errstate (invalid = "ignore" ):
563
+ xa *= self .N
564
+ # Negative values are out of range, but astype(int) would
565
+ # truncate them towards zero.
566
+ xa [xa < 0 ] = - 1
567
+ # xa == 1 (== N after multiplication) is not out of range.
568
+ xa [xa == self .N ] = self .N - 1
569
+ # Avoid converting large positive values to negative integers.
570
+ np .clip (xa , - 1 , self .N , out = xa )
571
+ xa = xa .astype (int )
587
572
# Set the over-range indices before the under-range;
588
573
# otherwise the under-range values get converted to over-range.
589
574
xa [xa > self .N - 1 ] = self ._i_over
590
575
xa [xa < 0 ] = self ._i_under
591
- if mask_bad is not None :
592
- xa [mask_bad ] = self ._i_bad
576
+ xa [mask_bad ] = self ._i_bad
593
577
594
578
if bytes :
595
579
lut = (self ._lut * 255 ).astype (np .uint8 )
@@ -610,7 +594,7 @@ def __call__(self, X, alpha=None, bytes=False):
610
594
# If the bad value is set to have a color, then we
611
595
# override its alpha just as for any other value.
612
596
613
- rgba = lut . take ( xa , axis = 0 , mode = 'clip' )
597
+ rgba = lut [ xa ]
614
598
if not np .iterable (X ):
615
599
# Return a tuple if the input was a scalar
616
600
rgba = tuple (rgba )
0 commit comments