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 arrow groupby na #60777

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

asharmalik19
Copy link

@asharmalik19 asharmalik19 force-pushed the fix-arrow-groupby-na branch 4 times, most recently from 0e61611 to 66330ee Compare January 29, 2025 21:35
@rhshadrach rhshadrach self-requested a review January 30, 2025 21:41
Comment on lines +1212 to +1213
# dictionary encode does nothing if an already encoded array is given
data = data.cast(data.type.value_type)
Copy link
Member

Choose a reason for hiding this comment

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

I think you're explaining why you have the cast here, but I'm not quite understanding it. Can you give a bit more details (just as a response here, and we can decide if the comment should be updated later).

Copy link
Author

Choose a reason for hiding this comment

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

If the input array is already a dictionary array then the dictionary encode function does nothing and hence the null_encoding parameter is ignored
https://arrow.apache.org/docs/python/generated/pyarrow.compute.dictionary_encode.html
Casting the array and then re-encoding it, ensures the proper use of null_encoding when NA values are desired in the output

Copy link
Member

@rhshadrach rhshadrach Feb 4, 2025

Choose a reason for hiding this comment

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

Am I correct in that this only needs to be done for pyarrow<15.0.0? If that is the case, then can you do this conditionally based on the version of PyArrow available.

from pandas.compat.pyarrow import pa_version_under15p0

Comment on lines 618 to 619
- Fixed bug in :meth:`ArrowExtensionArray.factorize` where NA values were dropped when input was dictionary-encoded even when dropna was set to False(:issue:`60567`)

Copy link
Member

Choose a reason for hiding this comment

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

Can you move this to an appropriate section below, I think ExtensionArray.

pandas/tests/extension/test_arrow.py Outdated Show resolved Hide resolved
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.

BUG: groupby with dropna=False and pa.dictionary drops NA values
2 participants