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: pd.replace changes dtype when using a dict to replace values even when there are no matches #53968

Closed

Conversation

ABizzinotto
Copy link
Contributor

@ABizzinotto
Copy link
Contributor Author

I might be missing something here, so thought I'd ask before changing tests. The solution I found is to convert the dtypes of the resulting dataframe after the replace operation back to the original if no replacement was made. For inplace operations, self is overridden when new_data is generated, meaning in order to retain a copy of the original dataframe, I have to copy it before that operation takes place. I then use the copy of the original dataframe to check if no replacements where made and update the dtypes. This, however, creates a new result dataframe before return, meaning the np.shares_memory tests for inplace operations start failing. Not sure if there's a different solution I'm missing or if these tests should be altered to accommodate this fix.

@phofl
Copy link
Member

phofl commented Jul 2, 2023

See comment in the issue, this is intended behavior

@mroeschke
Copy link
Member

Thanks but based on the discussion in #53539 this is the intended behavior so closing

@mroeschke mroeschke closed this Jul 6, 2023
@ABizzinotto ABizzinotto deleted the keep-dtypes-on-no-replacement branch October 3, 2023 15:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: pd.replace changes dtype when using a dict to replace values even when there are no matches
3 participants