@@ -59,6 +59,7 @@ def get_color_array(
59
59
v = pd .Series (values , dtype = object )
60
60
legit_indices = v [~ v .isna ()].index .values
61
61
legit_vals = v .dropna ().values
62
+ bogus_indices = v [v .isna ()].index .values # stash these for use later
62
63
# transform (non-NaN) values into class bins
63
64
bins = _classify (legit_vals , scheme = scheme , ** kwargs ).yb
64
65
@@ -69,13 +70,16 @@ def get_color_array(
69
70
# generate RBGA array and convert to series
70
71
rgbas = colormaps [cmap ](normalized_vals , bytes = True , alpha = alpha )
71
72
colors = pd .Series (list (rgbas ), index = legit_indices ).apply (np .array )
73
+ nan_colors = pd .Series (
74
+ [nan_color for i in range (len (bogus_indices ))], index = bogus_indices
75
+ ).apply (lambda x : np .array (x ).astype (np .uint8 ))
72
76
73
- # put colors in their correct places and fill empty with designated color
77
+ # put colors in their correct places and fill empty with specified color
74
78
v .update (colors )
75
- v = v . fillna ( f" { nan_color } " ). apply ( np . array )
79
+ v . update ( nan_colors )
76
80
77
81
# convert to hexcolors if preferred
78
82
if as_hex :
79
- colors = colors .apply (lambda x : to_hex (x / 255.0 ))
83
+ colors = v .apply (lambda x : to_hex (x / 255.0 ))
80
84
return colors .values
81
85
return np .stack (v .values )
0 commit comments