Skip to content

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 8 commits into from
Jan 28, 2021

Conversation

phofl
Copy link
Member

@phofl phofl commented Jan 23, 2021

@phofl phofl added Indexing Related to indexing on series/frames, not to indexes themselves Series Series data structure labels Jan 23, 2021
@jreback jreback added this to the 1.3 milestone Jan 26, 2021
@@ -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])
Copy link
Contributor

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)?

Copy link
Member Author

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:
Copy link
Member

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

Copy link
Member Author

@phofl phofl Jan 27, 2021

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

Copy link
Member

@jbrockmendel jbrockmendel Jan 27, 2021

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)

Copy link
Member Author

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

@jreback jreback merged commit 6e579ed into pandas-dev:master Jan 28, 2021
@jreback
Copy link
Contributor

jreback commented Jan 28, 2021

thanks @phofl

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Indexing Related to indexing on series/frames, not to indexes themselves Series Series data structure
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: Series.loc setitem with Series raises ValueError
3 participants