@@ -108,16 +108,42 @@ def _reparse_points(
108108 )
109109
110110
111+ def _warn_missing_groups (
112+ groups : str | list [str ],
113+ color_source_vector : pd .Categorical ,
114+ col_for_color : str | None = None ,
115+ ) -> None :
116+ """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 )
119+ if not missing :
120+ return
121+ col_label = f" '{ col_for_color } '" if col_for_color else ""
122+ if missing == set (groups_list ):
123+ logger .warning (
124+ f"None of the requested groups { sorted (missing )} were found in column{ col_label } . "
125+ "This usually means `groups` refers to values from a different column than `color`. "
126+ "The `groups` parameter selects categories of the column specified via `color`."
127+ )
128+ else :
129+ 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 )} ."
132+ )
133+
134+
111135def _filter_groups_transparent_na (
112136 groups : str | list [str ],
113137 color_source_vector : pd .Categorical ,
114138 color_vector : pd .Series | np .ndarray | list [str ],
139+ col_for_color : str | None = None ,
115140) -> tuple [np .ndarray , pd .Categorical , np .ndarray ]:
116141 """Return a boolean mask and filtered color vectors for groups filtering.
117142
118143 Used when ``na_color=None`` (fully transparent) so that non-matching
119144 elements are removed entirely instead of rendered invisibly.
120145 """
146+ _warn_missing_groups (groups , color_source_vector , col_for_color )
121147 keep = color_source_vector .isin (groups )
122148 filtered_csv = color_source_vector [keep ]
123149 filtered_cv = np .asarray (color_vector )[keep ]
@@ -301,17 +327,9 @@ def _render_shapes(
301327 # When groups are specified, filter out non-matching elements by default.
302328 # Only show non-matching elements if the user explicitly sets na_color.
303329 _na = render_params .cmap_params .na_color
304- if groups is not None and values_are_categorical and (_na .default_color_set or _na .alpha == "00" ):
305- assert color_source_vector is not None # guaranteed by values_are_categorical
306- _groups_list = [groups ] if isinstance (groups , str ) else groups
307- _missing = set (_groups_list ) - set (color_source_vector .categories )
308- if _missing :
309- logger .warning (
310- f"Groups { sorted (_missing )} not found in the values of '{ col_for_color } '. "
311- "The `groups` parameter filters values of the `color` column."
312- )
330+ if groups is not None and color_source_vector is not None and (_na .default_color_set or _na .alpha == "00" ):
313331 keep , color_source_vector , color_vector = _filter_groups_transparent_na (
314- groups , color_source_vector , color_vector
332+ groups , color_source_vector , color_vector , col_for_color = col_for_color
315333 )
316334 shapes = shapes [keep ].reset_index (drop = True )
317335 if len (shapes ) == 0 :
@@ -762,15 +780,8 @@ def _render_points(
762780 # Only show non-matching elements if the user explicitly sets na_color.
763781 _na = render_params .cmap_params .na_color
764782 if groups is not None and color_source_vector is not None and (_na .default_color_set or _na .alpha == "00" ):
765- _groups_list = [groups ] if isinstance (groups , str ) else groups
766- _missing = set (_groups_list ) - set (color_source_vector .categories )
767- if _missing :
768- logger .warning (
769- f"Groups { sorted (_missing )} not found in the values of '{ col_for_color } '. "
770- "The `groups` parameter filters values of the `color` column."
771- )
772783 keep , color_source_vector , color_vector = _filter_groups_transparent_na (
773- groups , color_source_vector , color_vector
784+ groups , color_source_vector , color_vector , col_for_color = col_for_color
774785 )
775786 n_points = int (keep .sum ())
776787 if n_points == 0 :
@@ -1322,6 +1333,7 @@ def _render_labels(
13221333 and color_source_vector is not None
13231334 and (_na .default_color_set or _na .alpha == "00" )
13241335 ):
1336+ _warn_missing_groups (groups , color_source_vector , col_for_color )
13251337 keep_vec = color_source_vector .isin (groups )
13261338 matching_ids = instance_id [keep_vec ]
13271339 keep_mask = np .isin (label .values , matching_ids )
0 commit comments