Skip to content

API: Series.__setitem__ with Series value #51386

Open
@jbrockmendel

Description

@jbrockmendel
orig = pd.Series(range(10))

key = pd.Series([6, 7])

ser = orig.copy()
ser[key._values] = key * 2
>>> ser
0     0
1     1
2     2
3     3
4     4
5     5
6    12
7    14
8     8
9     9
dtype: int64

ser = orig.copy()
ser.loc[key._values] = key * 2
>>> ser
0    0.0
1    1.0
2    2.0
3    3.0
4    4.0
5    5.0
6    NaN
7    NaN
8    8.0
9    9.0
dtype: float64

In .loc we do a .reindex on the value Series, but not in Series.__setitem__ (which goes through Series._set_values to mgr.setitem) using .iloc gets the __setitem__ behavior.

Maybe I just need some coffee, but it isn't obvious to me what the expected behavior is here cc @phofl

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugDeprecateFunctionality to remove in pandas

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions