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

Fixes #3762: Fix dataframe groupby aggregations when keys contain NaNs #3766

Merged
merged 2 commits into from
Sep 18, 2024

Conversation

stress-tess
Copy link
Member

@stress-tess stress-tess commented Sep 11, 2024

This PR (fixes #3762) using dataframe groupby with keys that contain NaNs would cause the aggregations to fail. To resolve this, we mask out the values that belong to the NaN segment

Before this PR:

>>> df = ak.DataFrame({"A":[1,2,2,np.nan],"B":[3,4,5,6], "C":[1,np.nan,2, 3]})
>>> df.groupby("A").count()
---------------------------------------------------------------------------
ValueError
...
ValueError: Attempt to group array using key array of different length

After this PR:

>>> df = ak.DataFrame({"A":[1,2,2,np.nan],"B":[3,4,5,6], "C":[1,np.nan,2, 3]})
>>> df.groupby("A").count()
     B  C
A
1.0  1  1
2.0  2  1 (2 rows x 2 columns)

>>> df.to_pandas().groupby("A").count()
     B  C
A
1.0  1  1
2.0  2  1

>>> df.groupby(["A","C"],as_index=False).count()
     A    C  B
0  1.0  1.0  1
1  2.0  2.0  1 (2 rows x 3 columns)

>>> df.to_pandas().groupby(["A","C"],as_index=False).count()
     A    C  B
0  1.0  1.0  1
1  2.0  2.0  1

Copy link
Contributor

@ajpotts ajpotts left a comment

Choose a reason for hiding this comment

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

Looks good! Thanks for doing this one!

tests/dataframe_test.py Show resolved Hide resolved
arkouda/dataframe.py Outdated Show resolved Hide resolved
arkouda/dataframe.py Show resolved Hide resolved
…ontain `NaN`s

This PR (fixes Bears-R-Us#3762) using dataframe groupby with keys that contain `NaN`s would cause the aggregations to fail. To resolve this, we mask out the values that belong to the `NaN` segment
tests/dataframe_test.py Show resolved Hide resolved
@stress-tess stress-tess added this pull request to the merge queue Sep 18, 2024
Merged via the queue into Bears-R-Us:master with commit e5723b3 Sep 18, 2024
10 checks passed
@stress-tess stress-tess deleted the 3762_df_gb_dropna_bug branch September 18, 2024 19:50
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.

mask values by isnan for dataframe groupby with dropna=True
2 participants