-
-
Notifications
You must be signed in to change notification settings - Fork 19.1k
BUG: fix .loc.__setitem__ not raising when using too many indexers #44656
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 3 commits
ca37c9c
c34acb2
d886470
5bae428
06eb7e4
453e3ba
8c53bba
8e44463
e5a768f
7880015
f83cfc8
b5c664d
f7bc4a0
8daced5
3ebf788
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 |
---|---|---|
|
@@ -1189,6 +1189,18 @@ def test_iloc_getitem_setitem_fancy_exceptions(self, float_frame): | |
# GH#32257 we let numpy do validation, get their exception | ||
float_frame.iloc[:, :, :] = 1 | ||
|
||
@pytest.mark.parametrize( | ||
"ser, keys", | ||
[(Series([10]), (0, 0)), (Series([1, 2, 3], index=list("abc")), (0, 1))], | ||
) | ||
def test_iloc_setitem_indexer_length(self, ser, keys): | ||
# GH#13831 | ||
with pytest.raises(IndexError, match="too many indices for array"): | ||
|
||
ser.iloc[keys] = 1000 | ||
|
||
with pytest.raises(IndexingError, match="Too many indexers"): | ||
ser.iloc[keys] | ||
|
||
# TODO(ArrayManager) "split" path doesn't properly implement DataFrame indexer | ||
@td.skip_array_manager_not_yet_implemented | ||
def test_iloc_frame_indexer(self): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2685,6 +2685,18 @@ def test_loc_with_period_index_indexer(): | |
tm.assert_frame_equal(df, df.loc[list(idx)]) | ||
|
||
|
||
def test_loc_setitem_multiindex_timestamp(): | ||
jreback marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# GH#13831 | ||
vals = np.random.randn(8, 6) | ||
idx = date_range("1/1/2000", periods=8) | ||
cols = ["A", "B", "C", "D", "E", "F"] | ||
df_mt = DataFrame(vals, index=idx, columns=cols) | ||
df_mt.loc[df_mt.index[1], ("A", "B")] = np.nan | ||
vals[1][0:2] = np.nan | ||
res = DataFrame(vals, index=idx, columns=cols) | ||
tm.assert_frame_equal(res, df_mt) | ||
phofl marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
|
||
def test_loc_getitem_multiindex_tuple_level(): | ||
# GH#27591 | ||
lev1 = ["a", "b", "c"] | ||
|
@@ -2715,6 +2727,20 @@ def test_loc_getitem_multiindex_tuple_level(): | |
assert result2 == 6 | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"ser, keys", | ||
[(Series([10]), (0, 0)), (Series([1, 2, 3], index=list("abc")), (0, 1))], | ||
) | ||
def test_loc_setitem_indexer_length(ser, keys): | ||
# GH#13831 | ||
msg = "Too many indexers" | ||
with pytest.raises(IndexingError, match=msg): | ||
ser.loc[keys] = 1000 | ||
|
||
with pytest.raises(IndexingError, match=msg): | ||
ser.loc[keys] | ||
|
||
|
||
|
||
class TestLocSeries: | ||
@pytest.mark.parametrize("val,expected", [(2 ** 63 - 1, 3), (2 ** 63, 4)]) | ||
def test_loc_uint64(self, val, expected): | ||
|
@@ -2889,11 +2915,11 @@ def test_loc_series_getitem_too_many_dimensions(self, indexer): | |
index=MultiIndex.from_tuples([("A", "0"), ("A", "1"), ("B", "0")]), | ||
data=[21, 22, 23], | ||
) | ||
msg = "Too many indices" | ||
with pytest.raises(ValueError, match=msg): | ||
msg = "Too many indexers" | ||
with pytest.raises(IndexingError, match=msg): | ||
ser.loc[indexer, :] | ||
|
||
with pytest.raises(ValueError, match=msg): | ||
with pytest.raises(IndexingError, match=msg): | ||
ser.loc[indexer, :] = 1 | ||
|
||
def test_loc_setitem(self, string_series): | ||
|
Uh oh!
There was an error while loading. Please reload this page.