Skip to content

BUG: pd.query odd behavior while working with dropped NA boolean Series #45876

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

Open
3 tasks done
Syndorik opened this issue Feb 8, 2022 · 1 comment
Open
3 tasks done
Labels
Bug expressions pd.eval, query

Comments

@Syndorik
Copy link

Syndorik commented Feb 8, 2022

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

import pandas as pd

df = pd.DataFrame(data={"a" : [True, False, None]})

# Throws keyerror
df.dropna().query("not a")

# Doesn't throw keyerror
df.dropna().query("a")

df.dropna().assign(a = lambda df: df.a.astype(bool)).query("not a")

Issue Description

The pd.DataFrame.query function works weirdly based on this example. I'm trying to use more method chaining in pandas, and when I tried what is shown in the example I've come up with the behavior (explained in the example).

It seems that if a column is not considered as bool first, the .query("not column") throws a KeyError, while .query("column") doesn't

Expected Behavior

I am unsure that this is a bug, or this behavior is exepcted.

Installed Versions

INSTALLED VERSIONS

commit : bb1f651
python : 3.9.10.final.0
python-bits : 64
OS : Linux
OS-release : 5.4.0-1063-aws
Version : #66~18.04.1-Ubuntu SMP Thu Jan 13 19:45:37 UTC 2022
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : C.UTF-8
LOCALE : en_US.UTF-8

pandas : 1.4.0
numpy : 1.22.2
pytz : 2021.3
dateutil : 2.8.2
pip : 22.0.3
setuptools : 59.8.0
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : 1.0.2
psycopg2 : None
jinja2 : 3.0.3
IPython : 7.31.1
pandas_datareader: None
bs4 : None
bottleneck : None
fastparquet : None
fsspec : 2022.01.0
gcsfs : None
matplotlib : 3.5.1
numba : None
numexpr : None
odfpy : None
openpyxl : 3.0.9
pandas_gbq : None
pyarrow : None
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : 1.8.0
sqlalchemy : 1.4.31
tables : None
tabulate : None
xarray : None
xlrd : 2.0.1
xlwt : None
zstandard : None
None

@Syndorik Syndorik added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Feb 8, 2022
@jbrockmendel
Copy link
Member

pls give the issue an informative title

@Syndorik Syndorik changed the title BUG: BUG: pd.query odd behavior while working with dropped NA boolean Series Feb 9, 2022
@mroeschke mroeschke added expressions pd.eval, query and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Feb 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug expressions pd.eval, query
Projects
None yet
Development

No branches or pull requests

3 participants