-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: loc setitem with missing integer slices does not raise #30921
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2922,6 +2922,9 @@ def is_int(v): | |
self._validate_indexer("slice", key.step, kind), | ||
) | ||
|
||
if kind == "loc" and not is_null_slicer: | ||
return self.slice_indexer(key.start, key.stop, key.step, kind=kind) | ||
|
||
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. 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. 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. hey sorry I haven't had time to work on this. |
||
# convert the slice to an indexer here | ||
|
||
# if we are mixed and have integers | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -915,8 +915,8 @@ def test_loc_setitem_empty_append_raises(self): | |
with pytest.raises(KeyError, match=msg): | ||
df.loc[[0, 1], "x"] = data | ||
|
||
msg = "cannot copy sequence with size 2 to array axis with dimension 0" | ||
with pytest.raises(ValueError, match=msg): | ||
msg = "cannot do slice indexing on .* with these indexers" | ||
with pytest.raises(TypeError, match=msg): | ||
df.loc[0:2, "x"] = data | ||
|
||
def test_indexing_zerodim_np_array(self): | ||
|
@@ -985,6 +985,19 @@ def test_loc_setitem_float_intindex(): | |
tm.assert_frame_equal(result, expected) | ||
|
||
|
||
@pytest.mark.parametrize("test_series", [False, True]) | ||
def test_loc_setitem_missing_integer_slice(test_series): | ||
# 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): | ||
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. Newline above this one |
||
if test_series: | ||
s = df["col1"] | ||
s.loc[0:2] = 10 | ||
else: | ||
df.loc[0:2] = 10 | ||
|
||
|
||
def test_loc_axis_1_slice(): | ||
# GH 10586 | ||
cols = [(yr, m) for yr in [2014, 2015] for m in [7, 8, 9, 10]] | ||
|
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.