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

BUG: Fix dtypes change using replace with nullable dtypes (#40732) #40864

Closed
wants to merge 6 commits into from
Closed

BUG: Fix dtypes change using replace with nullable dtypes (#40732) #40864

wants to merge 6 commits into from

Conversation

hasan-yaman
Copy link
Contributor

@hasan-yaman hasan-yaman commented Apr 10, 2021

@pep8speaks
Copy link

pep8speaks commented Apr 10, 2021

Hello @hasan-yaman! 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-04-12 18:30:53 UTC

@hasan-yaman hasan-yaman marked this pull request as draft April 10, 2021 14:53
@hasan-yaman hasan-yaman marked this pull request as ready for review April 12, 2021 20:06
nb = self.coerce_to_target_dtype(value)
if isinstance(
self.values, (IntegerArray, FloatingArray)
) and self._can_hold_element(value):
Copy link
Member

Choose a reason for hiding this comment

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

This seems like a very specific check, can you comment on why it is necessary / makes sense? Also, how does BooleanArray fit in here? Do we have tests on if replacement for BooleanArray works as expected?

Copy link
Member

@mzeitlin11 mzeitlin11 Apr 12, 2021

Choose a reason for hiding this comment

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

I'd guess the same underlying problem for nullable dtypes is also responsible for #40732 (comment), so it would be great if the patch were able to apply more generally and fix a case like that as well (unless you think the underlying issues are different).

Copy link
Contributor Author

@hasan-yaman hasan-yaman Apr 12, 2021

Choose a reason for hiding this comment

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

I focused the problem encounters in IntegerArray and FloatingArray that's why I added the check. But, i think i should focus on nullable arrays.
I think for the replace method, we don't have test that cover all the nullable arrays. Will try to add some.

[
(
[1.0, 2.0, 3.999, 4.4],
{1.0: 9},
Copy link
Member

@mzeitlin11 mzeitlin11 Apr 12, 2021

Choose a reason for hiding this comment

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

Since different paths are exercised by .replace(1.0, 9.0) and .replace({1.0, 9.0}), can the test be parameterized such that those cases can also be tested at the same time?

@mzeitlin11 mzeitlin11 added Bug NA - MaskedArrays Related to pd.NA and nullable extension arrays replace replace method labels Apr 12, 2021
Copy link
Member

@mzeitlin11 mzeitlin11 left a comment

Choose a reason for hiding this comment

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

Thanks for the pr @hasan-yaman! Left some comments, plus can you please add a whatsnew entry for 1.3?

@github-actions
Copy link
Contributor

This pull request is stale because it has been open for thirty days with no activity. Please update or respond to this comment if you're still interested in working on this.

@github-actions github-actions bot added the Stale label May 13, 2021
@simonjayhawkins
Copy link
Member

@hasan-yaman can you add a release note

@simonjayhawkins
Copy link
Member

Thanks @hasan-yaman for the PR. closing as stale. ping if you want to continue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug NA - MaskedArrays Related to pd.NA and nullable extension arrays replace replace method Stale
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: Dtypes change when using replace with nullable dtypes
4 participants