-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: Series.setitem raising ValueError when setting Series with scalar indexer #39358
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
Conversation
phofl
commented
Jan 23, 2021
- closes BUG: Series.loc setitem with Series raises ValueError #38303
- tests added / passed
- Ensure all linting tests pass, see here for how to run them
- whatsnew entry
� Conflicts: � doc/source/whatsnew/v1.3.0.rst
@@ -93,6 +93,22 @@ def test_setitem_negative_out_of_bounds(self): | |||
with pytest.raises(IndexError, match=msg): | |||
ser[-11] = "foo" | |||
|
|||
@pytest.mark.parametrize("ser_index", [0, 1]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you parameterize over tm.loc
and tm.at
(i assume that .iloc
/ .iat
take a different path)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, did not know that. Yes they do not align
@@ -2023,6 +2023,16 @@ def ravel(i): | |||
return ser._values.copy() | |||
return ser.reindex(ax)._values | |||
|
|||
elif is_integer(indexer) and self.ndim == 1: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can any of this be shared with the is_scalar branch on L2036? The _get_axis(1)
there looks wrong, and it looks sketchy that indexer
doesnt actually get used there
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could generalize the code, but this makes it quite hard to read. Have already tried this.
The second case is when setting a series for a row in a DataFrame while the first case is setting a series (with length one obviously) as a row of a series.
We do not need the indexer in the second case, since only aligning the series index with the dataframe columns
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
makes sense, thanks.
can at least the is_scalar check below be tightened to is_integer? (not necessarily in this PR)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, this is certainly possible
thanks @phofl |