@@ -805,8 +805,7 @@ def _get_rgba_and_mask(self, X, alpha=None, bytes=False):
805805 mask : np.ndarray
806806 Boolean array with True where the input is ``np.nan`` or masked.
807807 """
808- if not self ._isinit :
809- self ._init ()
808+ self ._ensure_inited ()
810809
811810 xa = np .array (X , copy = True )
812811 if not xa .dtype .isnative :
@@ -863,16 +862,13 @@ def __eq__(self, other):
863862 self .colorbar_extend != other .colorbar_extend ):
864863 return False
865864 # To compare lookup tables the Colormaps have to be initialized
866- if not self ._isinit :
867- self ._init ()
868- if not other ._isinit :
869- other ._init ()
865+ self ._ensure_inited ()
866+ other ._ensure_inited ()
870867 return np .array_equal (self ._lut , other ._lut )
871868
872869 def get_bad (self ):
873870 """Get the color for masked values."""
874- if not self ._isinit :
875- self ._init ()
871+ self ._ensure_inited ()
876872 return np .array (self ._lut [self ._i_bad ])
877873
878874 def set_bad (self , color = 'k' , alpha = None ):
@@ -881,8 +877,7 @@ def set_bad(self, color='k', alpha=None):
881877
882878 def get_under (self ):
883879 """Get the color for low out-of-range values."""
884- if not self ._isinit :
885- self ._init ()
880+ self ._ensure_inited ()
886881 return np .array (self ._lut [self ._i_under ])
887882
888883 def set_under (self , color = 'k' , alpha = None ):
@@ -891,8 +886,7 @@ def set_under(self, color='k', alpha=None):
891886
892887 def get_over (self ):
893888 """Get the color for high out-of-range values."""
894- if not self ._isinit :
895- self ._init ()
889+ self ._ensure_inited ()
896890 return np .array (self ._lut [self ._i_over ])
897891
898892 def set_over (self , color = 'k' , alpha = None ):
@@ -957,19 +951,21 @@ def with_alpha(self, alpha):
957951 if not 0 <= alpha <= 1 :
958952 raise ValueError ("'alpha' must be between 0 and 1, inclusive" )
959953 new_cm = self .copy ()
960- if not new_cm ._isinit :
961- new_cm ._init ()
954+ new_cm ._ensure_inited ()
962955 new_cm ._lut [:, 3 ] = alpha
963956 return new_cm
964957
965958 def _init (self ):
966959 """Generate the lookup table, ``self._lut``."""
967960 raise NotImplementedError ("Abstract class only" )
968961
969- def is_gray (self ):
970- """Return whether the colormap is grayscale."""
962+ def _ensure_inited (self ):
971963 if not self ._isinit :
972964 self ._init ()
965+
966+ def is_gray (self ):
967+ """Return whether the colormap is grayscale."""
968+ self ._ensure_inited ()
973969 return (np .all (self ._lut [:, 0 ] == self ._lut [:, 1 ]) and
974970 np .all (self ._lut [:, 0 ] == self ._lut [:, 2 ]))
975971
@@ -1363,9 +1359,7 @@ def monochrome(self):
13631359 # TODO: It's a separate discussion whether we need this property on
13641360 # colormaps at all (at least as public API). It's a very special edge
13651361 # case and we only use it for contours internally.
1366- if not self ._isinit :
1367- self ._init ()
1368-
1362+ self ._ensure_inited ()
13691363 return self .N <= 1 or np .all (self ._lut [0 ] == self ._lut [1 :self .N ])
13701364
13711365 def resampled (self , lutsize ):
0 commit comments