Skip to content

BUG: Fix unwanted type casting while replacing values in a DataFrame #33067

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

Closed
wants to merge 5 commits into from

Conversation

phofl
Copy link
Member

@phofl phofl commented Mar 27, 2020

As mentioned in #32988 here I think, that I have found a way to fix this, but I don't know, if this results in a desired behavior.

I would add tests after ensuring, that this does not break anything else.

Any thoughts about this?

@phofl phofl changed the title Fix unwanted type casting while replacing values in a DataFrame BUG: Fix unwanted type casting while replacing values in a DataFrame Mar 27, 2020
Copy link
Contributor

@jreback jreback left a comment

Choose a reason for hiding this comment

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

always tests first.

@phofl
Copy link
Member Author

phofl commented Mar 27, 2020

Thank, I'll follow this way in the future.

I added a test.

When you use a value, which is actually replaced in the test, the pd.NA is converted to np.nan, if the original DataFrame had float64 as datatype. The example given in the issue did not replace a value from the original DataFrame.

Don't know, if this is a desired behavior.

@jreback jreback added the Dtype Conversions Unexpected or buggy dtype conversions label Mar 27, 2020
to_replace=to_replace,
value=value,
inplace=inplace,
filter=filter,
regex=regex,
convert=convert,
)
blocks_converted = []
for ls_elem in block_replaced:
Copy link
Contributor

Choose a reason for hiding this comment

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

why is this logic not just in Block.replace itself? seems too complicated here

Copy link
Member Author

@phofl phofl Mar 27, 2020

Choose a reason for hiding this comment

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

I wanted to ensure, that the conversion would only take place, after the block was forcefully cast to an ObjectBlock before.

I can add it to the replace function, if that would be better.

Copy link
Member

Choose a reason for hiding this comment

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

I wanted to ensure, that the conversion would only take place, after the block was forcefully cast to an ObjectBlock before.

I can add it to the replace function, if that would be better.

the regression was caused by a clean-up to Block.replace (#27768), see #32988 (comment)

so fixing Block.replace as @jreback suggests seems more appropriate

@simonjayhawkins simonjayhawkins added the Regression Functionality that used to work in a prior pandas version label Mar 28, 2020
@simonjayhawkins
Copy link
Member

i've labelled this as a regression, see #32988 (comment) cc @jbrockmendel

@jreback
Copy link
Contributor

jreback commented Apr 7, 2020

can you merge master and see if you can simplify

to_replace=to_replace,
value=value,
inplace=inplace,
filter=filter,
regex=regex,
convert=convert,
)
blocks_converted = []
for ls_elem in block_replaced:
Copy link
Member

Choose a reason for hiding this comment

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

I wanted to ensure, that the conversion would only take place, after the block was forcefully cast to an ObjectBlock before.

I can add it to the replace function, if that would be better.

the regression was caused by a clean-up to Block.replace (#27768), see #32988 (comment)

so fixing Block.replace as @jreback suggests seems more appropriate

@simonjayhawkins
Copy link
Member

Thanks @phofl for looking into this. #32988 has been addressed via #34048.

@phofl phofl deleted the bug_type_casting_replace branch June 14, 2020 21:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Dtype Conversions Unexpected or buggy dtype conversions Regression Functionality that used to work in a prior pandas version
Projects
None yet
Development

Successfully merging this pull request may close these issues.

REGR: replace casts columns to object
3 participants