Skip to content

TST: add test to check dtype after replacing values in categorical Series inplace #53993

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

Conversation

natmokval
Copy link
Contributor

@natmokval natmokval marked this pull request as ready for review July 4, 2023 11:44
@natmokval
Copy link
Contributor Author

@mroeschke, I added a test to check if the dtype is being updated, when we replace values in a categorical Series inplace. Could you please take a look at my pr?

@MarcoGorelli MarcoGorelli self-requested a review July 6, 2023 09:28
result = pd.Series(data, dtype="category")
result.replace(to_replace="a", value="b", inplace=True)
expected = pd.Series(data_exp, dtype="category")
tm.assert_index_equal(expected.dtype.categories, result.dtype.categories)
Copy link
Member

Choose a reason for hiding this comment

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

Is this not covered by tm.assert_series_equal?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, tm.assert_series_equal(result, expected) should be sufficient

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you, I replaced tm.assert_index_equal with tm.assert_series_equal.

@mroeschke mroeschke added the Testing pandas testing functions or related to the test suite label Jul 6, 2023
@mroeschke mroeschke added this to the 2.1 milestone Jul 7, 2023
@mroeschke mroeschke merged commit 011d1d0 into pandas-dev:main Jul 7, 2023
@mroeschke
Copy link
Member

Thanks @natmokval

Daquisu pushed a commit to Daquisu/pandas that referenced this pull request Jul 8, 2023
…ries inplace (pandas-dev#53993)

* TST: add test to check dtype after replacing categorical Series inplace

* replace tm.assert_index_equal with tm.assert_series_equal
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: Series.replace doesn't update CategoricalDtype when inplace=True in pandas-2.0
3 participants