-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Inconsistent behaviour when assigning to series? #25548
Comments
Not sure I agree on expectation but this is rather nuanced. I think this should be raising a |
I'm not sure what the rules are for setitem. It seems like labels are ignored when the lengths are the same? In [48]: s3 = pd.Series([1, 2], index=['a', 'b'])
In [49]: target = s.copy()
In [50]: target[['a', 'b']] = s3; target
Out[50]:
a 1.0
b 2.0
c 0.0
d 0.0
dtype: float64
In [51]: target = s.copy()
In [52]: target[['a', 'b']] = s3[['b', 'a']]; target
Out[52]:
a 2.0
b 1.0
c 0.0
d 0.0
dtype: float64 But differing lengths triggers an alignment (output 2 and 3; though 3 is already aligned)? I wouldn't expect a SettingWithCopyWarning on the first one. The target isn't a (maybe) copy of another object. This is all in a single call to |
This seems to be consitent now and returns
Is this the expected output now? |
This is expected |
I tried executing the same example and got the same result. >>> s.loc[['a', 'b']] = s2
> >>> s # This should be the expected output or it works as intended (o/p with NaN one)?
> a 2.0
> b 2.0
> c 0.0
> d 0.0 |
take |
The behaviour of .loc[[]] with other dtypes and boolean dtypes in Index is different.
This is expected behaviour Should we have tests for say series2.loc[[]] for boolean indices being assigned with series3 that is another series with boolean indices? Example below
And if it's included, should it have one test or 2 separate tests( 1 for other dtypes in index, 1 for boolean dtypes in index). |
I noticed that
.loc
and__setitem__
behave very differently when assigning one series to a sub-range of another series:I'm not sure if this is intended behaviour but it seems odd.
I'm on pandas v. 0.24.1
The text was updated successfully, but these errors were encountered: