Skip to content

Pandas Series: maximum recursion error when replacing empty lists #21977

Closed
@FXLab91

Description

@FXLab91

I have a pandas Series containing lists. I wanted to replace empty lists with NaN. My first approach was using .replace, but that unexpectedly gave me a maximum recursion error.

I am using pandas 0.21.1 on Python 3.4, but other users had the same problem on 0.23

import numpy as np
import pandas as 
ts = pd.Series([[1], [2, 3], [], [4]])
ts.replace([], np.nan)

RuntimeError: maximum recursion depth exceeded in comparison

I achieved the desired output using:

ts[ts.apply(len) == 0] = np.nan

but I don't understand the maximum recursion error

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugReshapingConcat, Merge/Join, Stack/Unstack, Explode

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions