Skip to content

BUG: pandas.DataFrame.where doesn't work when cond is of Pandas Dtype #36521

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
JeremyVriens opened this issue Sep 21, 2020 · 2 comments
Closed
3 tasks done
Labels
Bug Duplicate Report Duplicate issue or pull request NA - MaskedArrays Related to pd.NA and nullable extension arrays

Comments

@JeremyVriens
Copy link

JeremyVriens commented Sep 21, 2020

  • 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

df = pd.DataFrame()
df["input_col"] = ["a", "b", "c"]
df["is_valid_row"] = pd.Series([1, 1, 0], dtype="Int64")
df["output_col"] = df[["input_col"]].where(df["is_valid_row"] == 1)  # AssertionError is thrown here

Problem description

The code snippet is simplified to show that when using pandas.DataFrame.where in combination with a Pandas Dtype (Int64) an AssertionError is raised.
Note that when df["input_col"] (= pandas.Series.where) or dtype="int64" (instead of "Int64") is used, the code behaves as expected.

This behaviour is broken since Pandas >= 1.1 (still an issue in 1.1.2).

Expected Output

output_col
a
b
NaN

Output of pd.show_versions()

INSTALLED VERSIONS

commit : 2a7d332
python : 3.8.2.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.18362
machine : AMD64
processor : Intel64 Family 6 Model 85 Stepping 4, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : English_United States.1252
pandas : 1.1.2
numpy : 1.19.2
pytz : 2020.1
dateutil : 2.8.1
pip : 20.2.3
setuptools : 46.2.0
Cython : None
pytest : 6.0.2
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : 1.3.3
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.11.2
IPython : 7.18.1
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pytables : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : 1.3.19
tables : None
tabulate : None
xarray : None
xlrd : 1.2.0
xlwt : None
numba : None

@JeremyVriens JeremyVriens added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Sep 21, 2020
@dsaxton
Copy link
Member

dsaxton commented Sep 21, 2020

Thanks @JeremyVriens, this is fixed by #36201 (also a duplicate of #35429)

@dsaxton dsaxton added NA - MaskedArrays Related to pd.NA and nullable extension arrays and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Sep 21, 2020
@dsaxton dsaxton added the Duplicate Report Duplicate issue or pull request label Sep 21, 2020
@JeremyVriens
Copy link
Author

@dsaxton thank you for the reply (and the fix)!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Duplicate Report Duplicate issue or pull request NA - MaskedArrays Related to pd.NA and nullable extension arrays
Projects
None yet
Development

No branches or pull requests

3 participants