Filter accepts syntax error and returns wrong results without warning.

This issue has been created since 2022-09-22.

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

data = {"ID": [10, 20, 30, 40, 50, 60, 70], "Age": [12, 14, 13, 12, 14, 13, 15], "NAME": ['AAA', 'BBB', 'CCC', 'DDD', 'EEE', 'FFF', 'GGG']}
df1 = pd.DataFrame(data)

# It is ok
print(df1.query('Age >= 12').shape)  # (7, 3)
print(df1[(df1.Age >= 12)].shape)  # (7, 3)
print(df1[df1.Age >= 12].shape)  # (7, 3)

# It is ok also
print(df1.query('Age >= 12 & ID > 50').shape) # (2, 3)
print(df1[(df1.Age >= 12) & (df1.ID > 50)].shape) # (2, 3)

# It is wrong, but with no warning gets wrong results
print(df1[(df1.Age >= 12) & df1.ID > 50].shape)  # (0, 3)
print(df1[df1.Age >= 12 & (df1.ID > 50)].shape)  # (7, 3)

Issue Description

The two syntaxes below are wrong, missing the parentheses. As a result, one of the conditions will not be executed.
df1[(df1.Age >= 12) & df1.ID > 50]
df1[df1.Age >= 12 & (df1.ID > 50)]

However, the library returns wrong values ​​without any kind of warning.

Expected Behavior

The command with the wrong syntax (missing the parentheses) should not be executed, it should return an error or warning.

Installed Versions

INSTALLED VERSIONS

commit : 66e3805
python : 3.7.14.final.0
python-bits : 64
OS : Linux
OS-release : 5.10.133+
Version : #1 SMP Fri Aug 26 08:44:51 UTC 2022
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 1.3.5
numpy : 1.21.6
pytz : 2022.2.1
dateutil : 2.8.2
pip : 21.1.3
setuptools : 57.4.0
Cython : 0.29.32
pytest : 3.6.4
hypothesis : None
sphinx : 1.8.6
blosc : None
feather : 0.4.1
xlsxwriter : None
lxml.etree : 4.9.1
html5lib : 1.0.1
pymysql : None
psycopg2 : 2.9.3 (dt dec pq3 ext lo64)
jinja2 : 2.11.3
IPython : 7.9.0
pandas_datareader: 0.9.0
bs4 : 4.6.3
bottleneck : None
fsspec : 2022.8.2
fastparquet : None
gcsfs : None
matplotlib : 3.2.2
numexpr : 2.8.3
odfpy : None
openpyxl : 3.0.10
pandas_gbq : 0.13.3
pyarrow : 6.0.1
pyxlsb : None
s3fs : None
scipy : 1.7.3
sqlalchemy : 1.4.41
tables : 3.7.0
tabulate : 0.8.10
xarray : 0.20.2
xlrd : 1.1.0
xlwt : 1.3.0
numba : 0.56.2

MarcoGorelli wrote this answer on 2022-09-22

Thanks for the report, but this is valid Python syntax - I don't think pandas can throw a warning or error here because it doesn't know what you were intending

closing for now then

More Details About Repo
Owner Name pandas-dev
Repo Name pandas
Full Name pandas-dev/pandas
Language Python
Created Date 2010-08-24
Updated Date 2022-09-29
Star Count 35374
Watcher Count 1122
Fork Count 15034
Issue Count 3579

YOU MAY BE INTERESTED

Issue Title Created Date Comment Count Updated Date
Windows build failed 5 2022-09-01 2022-09-02
Start RDP session from API 3 2021-01-13 2022-07-24
CVE-2021-28658 (Medium) detected in Django-1.11.29-py2.py3-none-any.whl - autoclosed 1 2021-04-08 2022-05-19
CVE-2020-11023 (Medium) detected in jquery-3.2.1.min.js 0 2021-02-18 2022-09-29
Running chatbot _ner without docker 2 2021-04-19 2022-08-17
CVE-2020-13091 (High) detected in pandas-0.19.0-cp27-cp27mu-manylinux1_x86_64.whl 0 2021-02-18 2022-07-26
CVE-2020-13254 (Medium) detected in Django-1.11.29-py2.py3-none-any.whl - autoclosed 1 2021-02-18 2022-07-26
CVE-2021-3281 (Medium) detected in Django-1.11.29-py2.py3-none-any.whl - autoclosed 1 2021-02-18 2022-05-19
CVE-2021-33430 (Medium) detected in numpy-1.19.2-cp37-cp37m-manylinux2010_x86_64.whl 0 2021-12-24 2022-09-14
CVE-2018-20060 (High) detected in urllib3-1.21.1-py2.py3-none-any.whl 0 2021-02-18 2022-07-26
CVE-2020-13596 (Medium) detected in Django-1.11.29-py2.py3-none-any.whl - autoclosed 1 2021-02-18 2022-07-26
CVE-2021-41496 (High) detected in numpy-1.19.2-cp37-cp37m-manylinux2010_x86_64.whl 0 2022-01-25 2022-05-19
CVE-2021-34141 (Medium) detected in numpy-1.19.2-cp37-cp37m-manylinux2010_x86_64.whl 0 2021-12-24 2022-07-26
CVE-2021-44420 (High) detected in Django-3.2.7-py3-none-any.whl 0 2022-01-25 2022-05-19
CVE-2021-45115 (High) detected in Django-3.2.7-py3-none-any.whl 0 2022-01-25 2022-07-26
CVE-2021-43854 (High) detected in nltk-3.4.5.zip 0 2021-12-25 2022-05-19
`brew cask install` fails if Docker or VLC have been installed manually 4 2020-01-25 2022-07-18
Support for more complicated server params 3 2021-07-08 2022-03-22
Regarding the setting method when using with typescript 0 2021-08-27 2022-08-08
For your consideration - chapters specification? 0 2022-07-26 2022-08-13
[New app]: Hashicorp Vagrant 0 2021-10-13 2022-08-29
Mblock 3.1.0 - Widgets in REDAXO 5.12.1 defekt 5 2021-06-21 2022-05-21
MS SQL: multiple excluding table names like 'TABLE' in schema 'SCHEMA' not parsing any data 0 2021-10-15 2022-08-28
Owl_plplot can't set device/driver independently of filename suffix 1 2021-01-24 2022-09-09
Missing tests/test_data/graph.pb ? 1 2021-09-13 2022-09-02
BOOST uses deprecated BOOST headers :-( 9 2021-12-01 2022-07-21
实体类实现SectionEntity导致itemType冲突 0 2021-12-27 2022-08-12
ci: add caching to more jobs 0 2021-07-27 2022-02-21
Refactor memoized values that have `sidebarStore` dependencies 1 2022-05-20 2022-09-22
Problem: data flow is embedded into ActivityContainer 0 2021-02-13 2022-08-22
Inconsistent unification in apply tactics 2 2022-01-20 2022-08-31
Missing modules & installation issues 15 2022-07-27 2022-08-26
Which distance is measured and output of the camera - D435i 3 2022-07-28 2022-08-26
https://www.pdfparser.org/ is not working 1 2022-02-23 2022-09-09
Scenario issue - End-User Prompts for VPP 1 2022-04-22 2022-09-23
VRL crashes when using `abort` nested in a function call argument 0 2022-06-07 2022-09-24
Link format in the sql-statement-change-column is wrong 2 2022-09-16 2022-09-18
Memory leak occurs with libvips 8.12.1 and pyvips 2.1.16 2 2021-12-26 2022-07-28
[Bug] One recording seems to be broken, showing actual text from the initial frame 1 2022-03-24 2022-09-14
[Success Image Report]: 1 2022-08-04 2022-09-07
[Remote Codespaces] Fail to debug in the Remote Codespace environment 8 2021-09-18 2022-07-25
Bug when shifting (sneaking) and jumping when there is 1 block directly above you 1 2022-02-25 2022-09-07
Renaming all azure-spring-boot-xxx to spring-cloud-azure-xxx 3 2021-09-26 2022-09-03
ImportError: DLL load failed: %1 is not a valid Win32 application. 1 2022-01-18 2022-08-18
LocalDateTime conversion fails on DST transition 1 2013-11-04 2022-09-29
[CoE Starter Kit - QUESTION] QUESTION 2 2022-05-25 2022-09-09
Add Subresource Integrity (SRI) on Highlight.js styles and scripts 7 2021-09-11 2022-09-03
Debian / Ubuntu base conda-notice.txt error 3 2022-09-05 2022-09-26
Merge Control.Monad.Writer.CPS from writer-cps-mtl 2 2019-05-16 2022-09-08
1 nodes.go:85] Failed to register node:"masterxx". err=datacenter 'DCNAME - Region' not found 18 2021-07-08 2022-09-23