ERR: better error message on invalid .query input · Issue #13139 · pandas-dev/pandas (original) (raw)
Code Sample
import pandas as pd import numpy as np df = pd.DataFrame({'A': 'foo bar foo bar foo bar foo foo'.split(), 'B': 'one one two three two two one three'.split(), 'C': np.arange(8), 'D': np.arange(8) * 2})
Expected output
If I run query with an empty string I should expect no output, however:
df.query('') Traceback (most recent call last): File "", line 1, in File "/opt/miniconda3/lib/python3.5/site-packages/pandas/core/frame.py", line 2140, in query res = self.eval(expr, **kwargs) File "/opt/miniconda3/lib/python3.5/site-packages/pandas/core/frame.py", line 2209, in eval return _eval(expr, inplace=inplace, **kwargs) File "/opt/miniconda3/lib/python3.5/site-packages/pandas/computation/eval.py", line 293, in eval return ret UnboundLocalError: local variable 'ret' referenced before assignment
The problem lies on the last line of https://github.com/pydata/pandas/blob/master/pandas/computation/eval.py
I'm not sure of a proper fix so I'm opening this issue instead of pull request.
output of pd.show_versions()
>>> pd.show_versions()
INSTALLED VERSIONS
------------------
commit: None
python: 3.5.1.final.0
python-bits: 64
OS: Linux
OS-release: 3.16.0-4-amd64
machine: x86_64
processor:
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
pandas: 0.18.0
nose: None
pip: 8.1.1
setuptools: 20.3
Cython: None
numpy: 1.11.0
scipy: 0.17.0
statsmodels: None
xarray: None
IPython: 4.2.0
sphinx: None
patsy: None
dateutil: 2.5.2
pytz: 2016.3
blosc: None
bottleneck: None
tables: 3.2.2
numexpr: 2.5.2
matplotlib: 1.5.1
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: None
httplib2: None
apiclient: None
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.8
boto: None