Skip to content

replace() alters unrelated values #7140

Closed
@toobaz

Description

@toobaz

I don't know if it is the same bug than #7126 (looks similar, but I didn't check the implementation), but

In [1]: from pandas import DataFrame

In [2]: import numpy as np

In [3]: df = DataFrame(index=range(2))

In [4]: df['a'] = True

In [5]: df.a

Out[5]: 
0    True
1    True
Name: a, dtype: bool

In [6]: df.replace([np.inf, -np.inf], np.nan).a

Out[6]: 
0   NaN
1   NaN
Name: a, dtype: float64

Notice the operation of doing such a replace on boolean variables may seem stupid... but it is less so if you consider that "replace" (differently from i.e. dropna) does not support a "subset" argument.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions