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

TST: Add test for duplicate by columns in groupby.agg using pd.namedAgg and asIndex=False #58579

Merged
merged 6 commits into from
May 6, 2024

Conversation

jasonmokk
Copy link
Contributor

@jasonmokk jasonmokk commented May 5, 2024

This PR adds a unit test to pandas/tests/groupby/test_groupby.py to verify the correct functionality of groupby.agg when passed in pd.NamedAgg objects with duplicate columns in the by argument, and with asIndex=False. Addresses GH #58446.

@jasonmokk jasonmokk marked this pull request as ready for review May 5, 2024 04:19
@jasonmokk jasonmokk changed the title TST: Add test for duplicate 'by' columns in 'groupby.agg' using 'pd.namedAgg' (#58446) TST: Add test for duplicate by columns in groupby.agg using pd.namedAgg (#58446) May 5, 2024
@jasonmokk jasonmokk changed the title TST: Add test for duplicate by columns in groupby.agg using pd.namedAgg (#58446) TST: Add test for duplicate 'by' columns in 'groupby.agg' using 'pd.namedAgg' (#58446) May 5, 2024
@jasonmokk jasonmokk changed the title TST: Add test for duplicate 'by' columns in 'groupby.agg' using 'pd.namedAgg' (#58446) TST: Add test for duplicate 'by' columns in 'groupby.agg' using 'pd.namedAgg' (#58446). pandas/tests/groupby/test_groupby.py May 5, 2024
@jasonmokk jasonmokk changed the title TST: Add test for duplicate 'by' columns in 'groupby.agg' using 'pd.namedAgg' (#58446). pandas/tests/groupby/test_groupby.py TST: Add test for duplicate 'by' columns in 'groupby.agg' using 'pd.namedAgg' (#58446) May 5, 2024
@jasonmokk jasonmokk changed the title TST: Add test for duplicate 'by' columns in 'groupby.agg' using 'pd.namedAgg' (#58446) TST: Add test for duplicate by columns in groupby.agg using pd.namedAgg (#58446) May 5, 2024
@@ -2954,3 +2954,38 @@ def test_groupby_dropna_with_nunique_unique():
)

tm.assert_frame_equal(result, expected)


@pytest.mark.parametrize("as_index_flag", [False])
Copy link
Member

Choose a reason for hiding this comment

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

You can just inline as_index=False in the groupby call below

Copy link
Contributor Author

@jasonmokk jasonmokk May 6, 2024

Choose a reason for hiding this comment

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

Got it, I've updated the PR!

@mroeschke mroeschke added the Testing pandas testing functions or related to the test suite label May 6, 2024
@jasonmokk jasonmokk changed the title TST: Add test for duplicate by columns in groupby.agg using pd.namedAgg (#58446) TST: Add test for duplicate by columns in groupby.agg using pd.namedAgg and asIndex=False May 6, 2024
@jasonmokk jasonmokk requested a review from mroeschke May 6, 2024 18:14
@mroeschke mroeschke added this to the 3.0 milestone May 6, 2024
@mroeschke mroeschke merged commit eb36970 into pandas-dev:main May 6, 2024
46 checks passed
@mroeschke
Copy link
Member

Thanks @jasonmokk

@jasonmokk jasonmokk deleted the test-groupby-agg-duplicates branch May 6, 2024 18:25
pmhatre1 pushed a commit to pmhatre1/pandas-pmhatre1 that referenced this pull request May 7, 2024
…amedAgg` and `asIndex=False` (pandas-dev#58579)

* implement test for GH pandas-dev#58446

* Reformat GH issue comment

* Directly inline as_index=False in groupby call

---------

Co-authored-by: Jason Mok <jasonmok@Jasons-MacBook-Air-4.local>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Testing pandas testing functions or related to the test suite
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: groupby.agg with as_index=False and duplicate columns in by fails with pd.NamedAgg.
2 participants