Skip to content

Conversation

@fujiaxiang
Copy link
Contributor

@fujiaxiang
Copy link
Contributor Author

There are two reasons for updating an old test case test_loc_setitem_empty_append_raises in test_loc.py:

  1. To raise the same error as .loc.__getitem__ when give slice does not exist

  2. The current error says cannot copy sequence with size 2 to array axis with dimension 0. This is not in line with what the user is trying to do: to add 2 new rows or columns. The error should be a TypeError because we don't current support (not yet implemented) using integer slice to add new rows / columns.

Hope that sounds convincing.
If not, let me know.

@fujiaxiang
Copy link
Contributor Author

This change has a huge impact on existing test cases. Let me investigate further.

@gfyoung gfyoung added Bug Indexing Related to indexing on series/frames, not to indexes themselves labels Jan 15, 2020
- :meth:`MultiIndex.get_loc` can't find missing values when input includes missing values (:issue:`19132`)
- Bug in :meth:`Series.__setitem__` incorrectly assigning values with boolean indexer when the length of new data matches the number of ``True`` values and new data is not a ``Series`` or an ``np.array`` (:issue:`30567`)
- Bug in indexing with a :class:`PeriodIndex` incorrectly accepting integers representing years, use e.g. ``ser.loc["2007"]`` instead of ``ser.loc[2007]`` (:issue:`30763`)
- Bug in :meth:`DataFrame.loc.__setitem__` and :meth:`Series.loc.__setitem__` not raising error when given integer slice does not exist in index (:issue:`26412`)
Copy link
Member

@gfyoung gfyoung Jan 15, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- Bug in :meth:`DataFrame.loc.__setitem__` and :meth:`Series.loc.__setitem__` not raising error when given integer slice does not exist in index (:issue:`26412`)
- Bug in :meth:`DataFrame.loc.__setitem__` and :meth:`Series.loc.__setitem__` not raising error when given integer slice that do not exist in the index (:issue:`26412`)

# GH 26412
df = DataFrame({"col1": [1, 2, 3]}, index=["a", "b", "c"])
msg = "cannot do slice indexing on .* with these indexers"
with pytest.raises(TypeError, match=msg):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Newline above this one


if kind == "loc" and not is_null_slicer:
return self.slice_indexer(key.start, key.stop, key.step, kind=kind)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is any of the validation on L2931-2948 relevant? can some or all of it be removed?

This likely affects some tests, see how this is handled in #31840.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hey sorry I haven't had time to work on this.
will close this PR in favor of #31840.

@fujiaxiang
Copy link
Contributor Author

closing this PR in favor of #31840.

@fujiaxiang fujiaxiang closed this Feb 28, 2020
@fujiaxiang fujiaxiang deleted the loc_setitem_with_integer_slices_does_not_raise branch March 20, 2021 02:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug Indexing Related to indexing on series/frames, not to indexes themselves

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Using .loc.__setitem__ with integer slices does not raise

3 participants