@@ -108,6 +108,37 @@ 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_set = {groups } if isinstance (groups , str ) else set (groups )
118+ missing = groups_set - set (color_source_vector .categories )
119+ if not missing :
120+ return
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 :
127+ logger .warning (
128+ f"None of the requested groups { missing_str } were found in{ col_label } . "
129+ "This usually means `groups` refers to values from a different column than `color`. "
130+ "The `groups` parameter selects categories of the column specified via `color`."
131+ )
132+ else :
133+ try :
134+ cats_str = str (sorted (color_source_vector .categories ))
135+ except TypeError :
136+ cats_str = str (list (color_source_vector .categories ))
137+ logger .warning (
138+ f"Groups { missing_str } were not found in{ col_label } and will be ignored. Available categories: { cats_str } ."
139+ )
140+
141+
111142def _filter_groups_transparent_na (
112143 groups : str | list [str ],
113144 color_source_vector : pd .Categorical ,
@@ -298,10 +329,13 @@ def _render_shapes(
298329
299330 values_are_categorical = color_source_vector is not None
300331
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+
301335 # When groups are specified, filter out non-matching elements by default.
302336 # Only show non-matching elements if the user explicitly sets na_color.
303337 _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" ):
338+ if groups is not None and color_source_vector is not None and (_na .default_color_set or _na .alpha == "00" ):
305339 keep , color_source_vector , color_vector = _filter_groups_transparent_na (
306340 groups , color_source_vector , color_vector
307341 )
@@ -750,6 +784,9 @@ def _render_points(
750784 if added_color_from_table and col_for_color is not None :
751785 _reparse_points (sdata_filt , element , points_pd_with_color , transformation_in_cs , coordinate_system )
752786
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+
753790 # When groups are specified, filter out non-matching elements by default.
754791 # Only show non-matching elements if the user explicitly sets na_color.
755792 _na = render_params .cmap_params .na_color
@@ -1298,6 +1335,9 @@ def _render_labels(
12981335 else :
12991336 assert color_source_vector is None
13001337
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+
13011341 # When groups are specified, zero out non-matching label IDs so they render as background.
13021342 # Only show non-matching labels if the user explicitly sets na_color.
13031343 _na = render_params .cmap_params .na_color
0 commit comments