Skip to content

PR: np.select function does not work with BooleanDtype Closes#43228 #19777

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

Closed
wants to merge 2 commits into from

Conversation

Navaneethan2503
Copy link

np.select function does not work with BooleanDtype Closes#43228
p
LETS US MERGE CHANGES

AFTER CHANGES 👍

df = pd.DataFrame({"col1": list("ABBC"), "col2": list("ZZXY")}).astype("string")
conditions = [
    (df["col2"] == "Z") & (df["col1"] == "A"),
    (df["col2"] == "Z") & (df["col1"] == "B"),
    (df["col1"] == "B"),
]
print((df["col2"] == "Z").dtype) #BooleanDtype
choices = ['yellow', 'blue', 'purple']
df['color'] = np.select(conditions, choices, default='black')

output:
col1 col2   color
0    A    Z  yellow
1    B    Z    blue
2    B    X  purple
3    C    Y   black


@rkern
Copy link
Member

rkern commented Aug 29, 2021

This is a pandas issue that they have indicated is something they need to fix on their side.

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.

2 participants