Skip to content

TST: Add testing to df.where() typecasting as per GH 42295 #43173

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 6 commits into from
Aug 26, 2021
Merged

TST: Add testing to df.where() typecasting as per GH 42295 #43173

merged 6 commits into from
Aug 26, 2021

Conversation

maximilianaccardo
Copy link
Contributor

@maximilianaccardo maximilianaccardo commented Aug 23, 2021

This makes sure that df.where does not cast floats to integers.

@pep8speaks
Copy link

pep8speaks commented Aug 23, 2021

Hello @maximilianaccardo! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2021-08-26 01:52:01 UTC

@maximilianaccardo maximilianaccardo marked this pull request as ready for review August 23, 2021 03:29
result = d1.where(pd.notnull(d1), None).dtypes
# make sure dtypes don't change
expected = d1.dtypes
tm.assert_series_equal(expected, result)
Copy link
Member

Choose a reason for hiding this comment

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

Instead of comparing the .dtype results. Could you compare the DataFrame result of result of d1.where(pd.notnull(d1), None)

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 the review. I updated it.

@mroeschke mroeschke added the Testing pandas testing functions or related to the test suite label Aug 23, 2021
def test_where_columns_casting():
# GH 42295

d1 = DataFrame({"a": [1.0, 2.0], "b": [3, np.nan]})
Copy link
Member

Choose a reason for hiding this comment

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

Please call df for consistency and create expected = df.copy() before applying where

Copy link
Member

Choose a reason for hiding this comment

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

Please create expected before calling where.

Copy link
Member

@phofl phofl left a comment

Choose a reason for hiding this comment

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

Could remove the comment, but lgtm

cc @mroeschke

@mroeschke mroeschke added this to the 1.4 milestone Aug 26, 2021
@mroeschke mroeschke merged commit c17656c into pandas-dev:master Aug 26, 2021
@mroeschke
Copy link
Member

Thanks @maximilianaccardo. Happy to have you tackle more issues that require tests.

feefladder pushed a commit to feefladder/pandas that referenced this pull request Sep 7, 2021
…v#43173)

* Add testing to df.where() typecasting as per GH 42295

* Fix style

* Directly compare data frames

* Fix pre-commit

* Rename dataframe to df

* create expected before calling where

Co-authored-by: Maximilian Carr <[email protected]>
Co-authored-by: Maximilian Carr <[email protected]>
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: df.where() inconsistently casts columns to integers
4 participants