-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
09cc7f4
BUG: Series.setitem raising ValueError when setting Series with scala…
phofl 2cb7a7b
Handle non object dtype series
phofl 78450b9
Remove brackets
phofl 33845f4
Improve performance
phofl 9e7a46a
Use is integer
phofl 29ba005
Merge branch 'master' of https://github.com/pandas-dev/pandas into 38303
phofl 38a66e9
Parametrize
phofl 371f88f
Replace is_scalar
phofl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -93,6 +93,24 @@ def test_setitem_negative_out_of_bounds(self): | |
with pytest.raises(IndexError, match=msg): | ||
ser[-11] = "foo" | ||
|
||
@pytest.mark.parametrize("indexer", [tm.loc, tm.at]) | ||
@pytest.mark.parametrize("ser_index", [0, 1]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you parameterize over There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, did not know that. Yes they do not align |
||
def test_setitem_series_object_dtype(self, indexer, ser_index): | ||
# GH#38303 | ||
ser = Series([0, 0], dtype="object") | ||
idxr = indexer(ser) | ||
idxr[0] = Series([42], index=[ser_index]) | ||
expected = Series([Series([42], index=[ser_index]), 0], dtype="object") | ||
tm.assert_series_equal(ser, expected) | ||
|
||
@pytest.mark.parametrize("index, exp_value", [(0, 42.0), (1, np.nan)]) | ||
def test_setitem_series(self, index, exp_value): | ||
# GH#38303 | ||
ser = Series([0, 0]) | ||
ser.loc[0] = Series([42], index=[index]) | ||
expected = Series([exp_value, 0]) | ||
tm.assert_series_equal(ser, expected) | ||
|
||
|
||
class TestSetitemSlices: | ||
def test_setitem_slice_float_raises(self, datetime_series): | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 thatindexer
doesnt actually get used thereThere 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