Skip to content

BUG: where method results in a different outputs with "object" and "string" dtypes #46366

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
3 tasks done
Leejung8763 opened this issue Mar 15, 2022 · 2 comments
Closed
3 tasks done
Labels

Comments

@Leejung8763
Copy link

Pandas version checks

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • I have confirmed this bug exists on the main branch of pandas.

Reproducible Example

df = pd.DataFrame({'A':["1","","3"]}, dtype="object")
df.where(df!="", np.nan, inplace=True)

df = pd.DataFrame({'A':["1","","3"]}, dtype="string")
df.where(df!="", np.nan, inplace=True)

Issue Description

I am getting different results when using the where method with different data type which are "object" and "string".

Expected Behavior

First, consider the dataframe with "object" and inplace=True options.

Then, I got a result that I expected.

df = pd.DataFrame({'A':["1","","3"]}, dtype="object")
df.where(df!="", np.nan, inplace=True)
    a
0   1
1   NaN
2   3

But, when I changed the dtypes "object" to "string", I got different result as below.

df = pd.DataFrame({'A':["1","","3"]}, dtype="string")
df.where(df!="", np.nan, inplace=True)
    A
0   <NA>
1   
2   <NA>

Installed Versions

pandas version: 1.3.5 , numpy version: 1.19.5

@Leejung8763 Leejung8763 added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Mar 15, 2022
@SeanRBurton
Copy link

SeanRBurton commented Mar 15, 2022

I am unable to replicate this on main. I get the behavior that you report for "object" in both cases.

@mroeschke
Copy link
Member

Yeah I believe this was address in 1.4 so closing

@simonjayhawkins simonjayhawkins removed the Needs Triage Issue that has not been reviewed by a pandas team member label Mar 25, 2022
@simonjayhawkins simonjayhawkins added this to the No action milestone Mar 25, 2022
simonjayhawkins added a commit to simonjayhawkins/pandas that referenced this issue Mar 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants