Skip to content

Series.where return unmodified series in upcasting corner case #3971

Closed
@dalejung

Description

@dalejung
import pandas as pd
import numpy as np
s = pd.Series(range(10))
s.where(s > 4, np.array([np.nan]))

Out[4]:
0    0
1    1
2    2
3    3
4    4
5    5
6    6
7    7
8    8
9    9
dtype: int64

The culprit is that if upcast is required, ser doesn't get changed in the com call. Since we're making a copy of self anyways, shouldn't we always pass in change?

        change = ser if inplace else None
        com._maybe_upcast_putmask(ser,~cond,other,change=change)

I didn't hit this organically and I'm assuming it's a fairly contrived example. Was just reading code and found this.

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