Skip to content

TST: groupby string dtype #52599

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

Merged
merged 2 commits into from
Apr 12, 2023

Conversation

srkds
Copy link
Contributor

@srkds srkds commented Apr 11, 2023

grouped = df.groupby("str_col", as_index=False)
avg = grouped.mean()
result = avg.dtypes[0]
tm.assert_equal(result, expected)
Copy link
Member

Choose a reason for hiding this comment

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

Could you instead compare the resulting DataFrame e.g.

result = df.groupby("str_col", as_index=False)
expected = DataFrame(...)
tm.assert_frame_equal(result, expected)

Copy link
Contributor Author

@srkds srkds Apr 12, 2023

Choose a reason for hiding this comment

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

Got it!

My bad I didn't know about assert_frame_equal. Thanks!
I read about it here, It will compare dtypes. Sounds good 👍

Are these the required changes?

expected = DataFrame({"str_col": ["a", "b", "c",], "num_col": [1.5, 2.0, 3.0]})
expected["str_col"] = expected['str_col'].astype("string")
result=grouped.mean()
tm.assert_frame_equal(result,expected)

Copy link
Member

Choose a reason for hiding this comment

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

Yes

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes

Thanks for confirming.

@mroeschke mroeschke added the Testing pandas testing functions or related to the test suite label Apr 11, 2023
@mroeschke mroeschke added this to the 2.1 milestone Apr 12, 2023
@mroeschke mroeschke merged commit a6d5db7 into pandas-dev:main Apr 12, 2023
@mroeschke
Copy link
Member

Thanks @srkds

@srkds
Copy link
Contributor Author

srkds commented Apr 13, 2023

Thanks @mroeschke for the review 🙏

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 drops string dtype
2 participants