Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

tomcarter23
Copy link
Member

@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