Skip to content

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

Closed
@hannahawalsh

Description

@hannahawalsh

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions