Skip to content

Inconsistent behaviour when assigning to series? #25548

Closed
@mwiebusch78

Description

@mwiebusch78

I noticed that .loc and __setitem__ behave very differently when assigning one series to a sub-range of another series:

>>> s = pd.Series(0.0, index=list('abcd'))
>>> s1 = pd.Series(1.0, index=list('ab'))
>>> s2 = pd.Series(2.0, index=list('xy'))
>>> s[['a', 'b']] = s2
>>> s  # names of s2 are ignored as expected
a    2.0
b    2.0
c    0.0
d    0.0
dtype: float64
>>> s.loc[['a', 'b']] = s2
>>> s  # not expected!!
a    NaN
b    NaN
c    0.0
d    0.0
dtype: float64
>>> s.loc[['a', 'b']] = s1
>>> s  # everything's fine if the indices match
a    1.0
b    1.0
c    0.0
d    0.0
dtype: float64

I'm not sure if this is intended behaviour but it seems odd.

I'm on pandas v. 0.24.1

Metadata

Metadata

Assignees

Labels

IndexingRelated to indexing on series/frames, not to indexes themselvesNeeds TestsUnit test(s) needed to prevent regressionsgood first issue

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions