Skip to content
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

RecursionError with DataFrame.replace() where to_replace is an empty list #26567

Closed
hannahawalsh opened this issue May 29, 2019 · 1 comment
Closed

Comments

@hannahawalsh
Copy link

Code Sample, a copy-pastable example if possible

import pandas as pd

df = pd.DataFrame([1,2,3,4,5])
df.replace([], 99, inplace=False)

Problem description

The current output is a recursion error. It is throwing an exception which then goes into an infinite exception loop (During handling of the above exception, another exception occurred), which finally breaks due to maximum recursion depth reached:

Expected Output

The expected output of the code is to replace nothing with 99. I am running into this issue when running through a list of lists and so it is unknown whether a specific list will be empty or not.

Output of pd.show_versions()

[paste the output of pd.show_versions() here below this line]
INSTALLED VERSIONS

commit: None
python: 3.6.3.final.0
python-bits: 64
OS: Linux
OS-release: 4.15.0-1032-gcp
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: en_US.UTF-8
LANG: en_US.UTF-8
LOCALE: en_US.UTF-8

pandas: 0.23.3
pytest: 4.5.0
pip: 18.1
setuptools: 38.4.0
Cython: 0.29.7
numpy: 1.12.1
scipy: 0.19.1
pyarrow: None
xarray: None
IPython: 6.5.0
sphinx: None
patsy: 0.4.1
dateutil: 2.6.1
pytz: 2017.3
blosc: None
bottleneck: None
tables: None
numexpr: 2.6.4
feather: None
matplotlib: 2.1.0
openpyxl: 2.5.0b1
xlrd: 1.1.0
xlwt: None
xlsxwriter: None
lxml: 4.1.1
bs4: 4.6.0
html5lib: 0.9999999
sqlalchemy: 1.1.13
pymysql: None
psycopg2: 2.7.4 (dt dec pq3 ext lo64)
jinja2: 2.10
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None

@mroeschke
Copy link
Member

This was fixed in 0.24.0 by #22083 and is available in the latest version of pandas.

In [2]: pd.__version__
Out[2]: '0.25.0.dev0+615.g998a0deea'

In [3]: import pandas as pd
   ...:
   ...: df = pd.DataFrame([1,2,3,4,5])
   ...: df.replace([], 99, inplace=False)
Out[3]:
   0
0  1
1  2
2  3
3  4
4  5

@mroeschke mroeschke added this to the No action milestone May 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants