You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
importpandasaspddf=pd.DataFrame((1,2,3), columns=['a#'])
df.query('a# > 2')
-------------------------------KeyErrorTraceback (mostrecentcalllast)
Filed:\Applications\Python\Python311\Lib\site-packages\pandas\core\computation\scope.py:231, inScope.resolve(self, key, is_local)
230ifself.has_resolvers:
-->231returnself.resolvers[key]
233# if we're here that means that we have no locals and we also have234# no resolversFiled:\Applications\Python\Python311\Lib\collections\__init__.py:1006, inChainMap.__getitem__(self, key)
1005pass->1006returnself.__missing__(key)
Filed:\Applications\Python\Python311\Lib\collections\__init__.py:998, inChainMap.__missing__(self, key)
997def__missing__(self, key):
-->998raiseKeyError(key)
KeyError: 'a'Duringhandlingoftheaboveexception, anotherexceptionoccurred:
KeyErrorTraceback (mostrecentcalllast)
Filed:\Applications\Python\Python311\Lib\site-packages\pandas\core\computation\scope.py:242, inScope.resolve(self, key, is_local)
238try:
239# last ditch effort we look in temporaries240# these are created when parsing indexing expressions
...
242returnself.temps[key]
243exceptKeyErroraserr:
-->244raiseUndefinedVariableError(key, is_local) fromerrUndefinedVariableError: name'a'isnotdefined
Issue Description
The query function seems to treat symbol # as a comment, it did not work as expected.
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
Issue Description
The
query
function seems to treat symbol#
as a comment, it did not work as expected.I also try to execute
it still throws an exception
Expected Behavior
like df[df['a#'] > 2]
Installed Versions
INSTALLED VERSIONS
commit : d9cdd2e
python : 3.11.6.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.22631
machine : AMD64
processor : Intel64 Family 6 Model 183 Stepping 1, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : Chinese (Simplified)_China.936
pandas : 2.2.2
numpy : 1.26.3
pytz : 2023.3.post1
dateutil : 2.8.2
setuptools : 65.5.0
pip : 24.0
Cython : 3.0.8
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.1.3
IPython : 8.20.0
pandas_datareader : None
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : 4.12.2
bottleneck : None
dataframe-api-compat : None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : 3.8.2
numba : None
numexpr : None
odfpy : None
openpyxl : 3.1.2
pandas_gbq : None
pyarrow : None
pyreadstat : None
python-calamine : None
pyxlsb : None
s3fs : None
scipy : 1.11.4
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
zstandard : None
tzdata : 2023.4
qtpy : None
pyqt5 : None
The text was updated successfully, but these errors were encountered: