@@ -114,36 +114,41 @@ def _warn_missing_groups(
114114 col_for_color : str | None = None ,
115115) -> None :
116116 """Warn when ``groups`` contains values absent from the color column's categories."""
117- groups_list = [ groups ] if isinstance (groups , str ) else list (groups )
118- missing = set ( groups_list ) - set (color_source_vector .categories )
117+ groups_set = { groups } if isinstance (groups , str ) else set (groups )
118+ missing = groups_set - set (color_source_vector .categories )
119119 if not missing :
120120 return
121- col_label = f" '{ col_for_color } '" if col_for_color else ""
122- if missing == set (groups_list ):
121+ col_label = f" '{ col_for_color } '" if col_for_color else " the color column"
122+ try :
123+ missing_str = str (sorted (missing ))
124+ except TypeError :
125+ missing_str = str (list (missing ))
126+ if missing == groups_set :
123127 logger .warning (
124- f"None of the requested groups { sorted ( missing ) } were found in column { col_label } . "
128+ f"None of the requested groups { missing_str } were found in{ col_label } . "
125129 "This usually means `groups` refers to values from a different column than `color`. "
126130 "The `groups` parameter selects categories of the column specified via `color`."
127131 )
128132 else :
133+ try :
134+ cats_str = str (sorted (color_source_vector .categories ))
135+ except TypeError :
136+ cats_str = str (list (color_source_vector .categories ))
129137 logger .warning (
130- f"Groups { sorted (missing )} were not found in column{ col_label } and will be ignored. "
131- f"Available categories: { sorted (color_source_vector .categories )} ."
138+ f"Groups { missing_str } were not found in{ col_label } and will be ignored. Available categories: { cats_str } ."
132139 )
133140
134141
135142def _filter_groups_transparent_na (
136143 groups : str | list [str ],
137144 color_source_vector : pd .Categorical ,
138145 color_vector : pd .Series | np .ndarray | list [str ],
139- col_for_color : str | None = None ,
140146) -> tuple [np .ndarray , pd .Categorical , np .ndarray ]:
141147 """Return a boolean mask and filtered color vectors for groups filtering.
142148
143149 Used when ``na_color=None`` (fully transparent) so that non-matching
144150 elements are removed entirely instead of rendered invisibly.
145151 """
146- _warn_missing_groups (groups , color_source_vector , col_for_color )
147152 keep = color_source_vector .isin (groups )
148153 filtered_csv = color_source_vector [keep ]
149154 filtered_cv = np .asarray (color_vector )[keep ]
@@ -324,12 +329,15 @@ def _render_shapes(
324329
325330 values_are_categorical = color_source_vector is not None
326331
332+ if groups is not None and color_source_vector is not None :
333+ _warn_missing_groups (groups , color_source_vector , col_for_color )
334+
327335 # When groups are specified, filter out non-matching elements by default.
328336 # Only show non-matching elements if the user explicitly sets na_color.
329337 _na = render_params .cmap_params .na_color
330338 if groups is not None and color_source_vector is not None and (_na .default_color_set or _na .alpha == "00" ):
331339 keep , color_source_vector , color_vector = _filter_groups_transparent_na (
332- groups , color_source_vector , color_vector , col_for_color = col_for_color
340+ groups , color_source_vector , color_vector
333341 )
334342 shapes = shapes [keep ].reset_index (drop = True )
335343 if len (shapes ) == 0 :
@@ -776,12 +784,15 @@ def _render_points(
776784 if added_color_from_table and col_for_color is not None :
777785 _reparse_points (sdata_filt , element , points_pd_with_color , transformation_in_cs , coordinate_system )
778786
787+ if groups is not None and color_source_vector is not None :
788+ _warn_missing_groups (groups , color_source_vector , col_for_color )
789+
779790 # When groups are specified, filter out non-matching elements by default.
780791 # Only show non-matching elements if the user explicitly sets na_color.
781792 _na = render_params .cmap_params .na_color
782793 if groups is not None and color_source_vector is not None and (_na .default_color_set or _na .alpha == "00" ):
783794 keep , color_source_vector , color_vector = _filter_groups_transparent_na (
784- groups , color_source_vector , color_vector , col_for_color = col_for_color
795+ groups , color_source_vector , color_vector
785796 )
786797 n_points = int (keep .sum ())
787798 if n_points == 0 :
@@ -1324,6 +1335,9 @@ def _render_labels(
13241335 else :
13251336 assert color_source_vector is None
13261337
1338+ if groups is not None and color_source_vector is not None :
1339+ _warn_missing_groups (groups , color_source_vector , col_for_color )
1340+
13271341 # When groups are specified, zero out non-matching label IDs so they render as background.
13281342 # Only show non-matching labels if the user explicitly sets na_color.
13291343 _na = render_params .cmap_params .na_color
@@ -1333,7 +1347,6 @@ def _render_labels(
13331347 and color_source_vector is not None
13341348 and (_na .default_color_set or _na .alpha == "00" )
13351349 ):
1336- _warn_missing_groups (groups , color_source_vector , col_for_color )
13371350 keep_vec = color_source_vector .isin (groups )
13381351 matching_ids = instance_id [keep_vec ]
13391352 keep_mask = np .isin (label .values , matching_ids )
0 commit comments