Skip to content

Comments

Bug Fix: Invalid group detected for dtype = "boolean" when plotting#179

Open
tomcarter23 wants to merge 1 commit intomainfrom
fix-check-bool-dtype
Open

Bug Fix: Invalid group detected for dtype = "boolean" when plotting#179
tomcarter23 wants to merge 1 commit intomainfrom
fix-check-bool-dtype

Conversation

@tomcarter23
Copy link

@tomcarter23 tomcarter23 commented Jun 15, 2023

When using the attr_distr_plot function the following error was encountered:

File ~/venv/lib/python3.8/site-packages/fairlens/plot/distr.py:77, in distr_plot(df, target_attr, groups, distr_type, show_hist, show_curve, shade, normalize, cmap, ax)
     74 if ax is None:
     75     ax = plt.gca()
---> 77 preds = utils.get_predicates_mult(df, groups)
     79 cmap = cmap or sns.color_palette("deep")
     80 palette = itertools.cycle(cmap)

File ~/venv/lib/python3.8/site-packages/fairlens/utils.py:318, in get_predicates_mult(df, groups)
    316     else:
    317         if not isinstance(group, pd.Series) or group.dtype != "bool":
--> 318             raise ValueError(
    319                 "Invalid group detected. Groups must be either dictionaries or pandas series' of bools."
    320             )
    322         predicates[i] = group
    324 # Check all attributes are valid

ValueError: Invalid group detected. Groups must be either dictionaries or pandas series' of bools.

This was because the groups were created with type "boolean" which incorrectly fails the comparison group.dtype != "bool". Using the pandas is_bool_dtype avoids this

@tomcarter23 tomcarter23 changed the title Fix: Invalid group detected for dtype = "boolean" when plotting Bug Fix: Invalid group detected for dtype = "boolean" when plotting Jun 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant