Skip to content

BUG: Recursion error when querying empty df #35391

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
2 of 3 tasks
klieret opened this issue Jul 23, 2020 · 5 comments
Closed
2 of 3 tasks

BUG: Recursion error when querying empty df #35391

klieret opened this issue Jul 23, 2020 · 5 comments
Labels
Bug Duplicate Report Duplicate issue or pull request expressions pd.eval, query

Comments

@klieret
Copy link
Contributor

klieret commented Jul 23, 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(columns=["a", "b"])
df.query("(a+b)==1")

NOTE: Under some circumstances the same might happen when the colums only contain np.nans but I couldn't get a MWE yet.

Problem description

Throws recursion error.

Expected Output

Empty df.

Output of pd.show_versions()

INSTALLED VERSIONS

commit : None
python : 3.7.5.final.0
python-bits : 64
OS : Linux
OS-release : 5.3.0-62-generic
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 1.0.5
numpy : 1.18.1
pytz : 2019.2
dateutil : 2.7.3
pip : 18.1
setuptools : 41.1.0
Cython : None
pytest : 5.3.2
hypothesis : None
sphinx : 3.0.0
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 4.5.0
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.10.3
IPython : 5.8.0
pandas_datareader: None
bs4 : 4.9.1
bottleneck : None
fastparquet : None
gcsfs : None
lxml.etree : 4.5.0
matplotlib : 3.2.1
numexpr : 2.7.1
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pytables : None
pytest : 5.3.2
pyxlsb : None
s3fs : None
scipy : 1.4.1
sqlalchemy : 1.3.16
tables : 3.6.1
tabulate : 0.8.7
xarray : None
xlrd : None
xlwt : None
xlsxwriter : None
numba : None

@klieret klieret added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Jul 23, 2020
@klieret
Copy link
Contributor Author

klieret commented Jul 23, 2020

Similar issue win NaNs:

import pandas as pd
import numpy as np
df = pd.DataFrame({"a": [np.nan], "b": [np.nan]}, dtype="object")
df.query("(a+b)==1")

also raises a recursion error.

@simonjayhawkins
Copy link
Member

Thanks @klieret for the report. I can confirm the same error on master and 0.25.3

@simonjayhawkins simonjayhawkins added expressions pd.eval, query and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Jul 23, 2020
@klieret
Copy link
Contributor Author

klieret commented Jul 23, 2020

So for anyone having the same problem, a

df = df.astype({col: "float64" for col in df.columns})

will save you from this issue. The problem seems to occur when the dtype of the column is set to object.

@simonjayhawkins
Copy link
Member

The problem seems to occur when the dtype of the column is set to object.

yes, it seems that even if the df is not empty or eval is used and only perform the addition, still raises RecursionError

>>> df = pd.DataFrame({"a": [1,2], "b": [1,2]}, dtype="object")
>>> df
   a  b
0  1  1
1  2  2
>>>
>>> df.eval("a+b")
...
RecursionError: maximum recursion depth exceeded

@simonjayhawkins
Copy link
Member

This issue appears to be a duplicate of #27639 and #34044 so closing. LMK is I misunderstood something and I'll reopen.

@simonjayhawkins simonjayhawkins added the Duplicate Report Duplicate issue or pull request label Jul 23, 2020
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 expressions pd.eval, query
Projects
None yet
Development

No branches or pull requests

2 participants