Skip to content

BUG: df.where() shows no effects when inplace=True #42369

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
MemphisMeng opened this issue Jul 4, 2021 · 0 comments
Closed
3 tasks

BUG: df.where() shows no effects when inplace=True #42369

MemphisMeng opened this issue Jul 4, 2021 · 0 comments
Labels
Bug Needs Triage Issue that has not been reviewed by a pandas team member

Comments

@MemphisMeng
Copy link

MemphisMeng commented Jul 4, 2021

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

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

  • (optional) I have confirmed this bug exists on the master branch of pandas.


Note: Please read this guide detailing how to provide the necessary information for us to reproduce your bug.

Code Sample, a copy-pastable example

import pandas as pd
import numpy as np

d1 = pd.DataFrame({"a": [1.0, 2.0], 'b': [3, np.nan]})
print('\nd1:')
print(d1)

print('\nd1.where(pd.notnull(d1), None, inplace=True):')
d1.where(pd.notnull(d1), None, inplace=True)

print('\nd1:')
print(d1)

d2 = pd.DataFrame({"a": [1.0, 2.0], 'b': [3, np.nan]})
print('\nd2:')
print(d2)

print('\nd2.where(pd.notnull(d2), None, inplace=True):')
d2.where(pd.notnull(d2), -1, inplace=True)

print('\nd2:')
print(d2)

Problem description

The result shows as follows. This means that if I set inplace to True, and the value of parameter "other" is None, then the manipulation isn't effective on the dataframe itself. This issue is kind of related to BUG#42295. Similarly, the bug doesn't show up if the value of other is a float/int type value.

d1:
     a    b
0  1.0  3.0
1  2.0  NaN

d1.where(pd.notnull(d1), None, inplace=True):

d1:
     a    b
0  1.0  3.0
1  2.0  NaN

d2:
     a    b
0  1.0  3.0
1  2.0  NaN

d2.where(pd.notnull(d2), None, inplace=True):

d2:
     a    b
0  1.0  3.0
1  2.0 -1.0

Expected Output

Output of pd.show_versions()

INSTALLED VERSIONS

commit : b5958ee
python : 3.7.10.final.0
python-bits : 64
OS : Linux
OS-release : 5.4.104+
Version : #1 SMP Sat Jun 5 09:50:34 PDT 2021
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 1.1.5
numpy : 1.19.5
pytz : 2018.9
dateutil : 2.8.1
pip : 19.3.1
setuptools : 57.0.0
Cython : 0.29.23
pytest : 3.6.4
hypothesis : None
sphinx : 1.8.5
blosc : None
feather : 0.4.1
xlsxwriter : None
lxml.etree : 4.2.6
html5lib : 1.0.1
pymysql : None
psycopg2 : 2.7.6.1 (dt dec pq3 ext lo64)
jinja2 : 2.11.3
IPython : 5.5.0
pandas_datareader: 0.9.0
bs4 : 4.6.3
bottleneck : 1.3.2
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : 3.2.2
numexpr : 2.7.3
odfpy : None
openpyxl : 2.5.9
pandas_gbq : 0.13.3
pyarrow : 3.0.0
pytables : None
pyxlsb : None
s3fs : None
scipy : 1.4.1
sqlalchemy : 1.4.18
tables : 3.4.4
tabulate : 0.8.9
xarray : 0.18.2
xlrd : 1.1.0
xlwt : 1.3.0
numba : 0.51.2

@MemphisMeng MemphisMeng added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Jul 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Needs Triage Issue that has not been reviewed by a pandas team member
Projects
None yet
Development

No branches or pull requests

1 participant