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

fix(python): allow map_dict on categorical dtype #7097

Merged

Conversation

coinflip112
Copy link
Contributor

See #7077

@github-actions github-actions bot added fix Bug fix python Related to Python Polars labels Feb 22, 2023
@ritchie46
Copy link
Member

Thanks! Can you undraft? It should be good to go.

@coinflip112 coinflip112 marked this pull request as ready for review February 22, 2023 13:39
@coinflip112
Copy link
Contributor Author

Done :)

@ritchie46 ritchie46 merged commit 54eb6b0 into pola-rs:master Feb 22, 2023
@cmdlineluser
Copy link
Contributor

Not sure if this is the correct place to comment - but I think if you set the dtype on the 2nd series too it will fix #7140

@coinflip112
Copy link
Contributor Author

Not sure if this is the correct place to comment - but I think if you set the dtype on the 2nd series too it will fix #7140

The issue is that I'm not sure to what I would be setting the dtype. It can't be the same dtype as the keys of the dictionary.
We would need to infer the type of the values of the mapping dictionary (and this is basically done by polars when the series is created). Maybe we could add an argument which would govern the output type 🤷 Not a fan of the idea though.

@@ -6296,6 +6299,7 @@ def inner_with_default(s: pli.Series) -> pli.Series:
df = s.to_frame().unnest(s.name) if s.dtype == Struct else s.to_frame()

column = df.columns[0]
input_dtype = df.select(column).dtypes[0]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe replace with: input_dtype = df.dtypes[0]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in #7217. I guess I didn't fully realize that we always operate on the first field in the struct 😓

@cmdlineluser
Copy link
Contributor

My bad, I was only thinking in terms of strings/categoricals for some reason - missing the fact that one could be returning a different type from the dict.

I thought the input_dtype could be used if the result was all nulls.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix Bug fix python Related to Python Polars
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants