Skip to content

Commit f646ea0

Browse files
authored
TST: setting value at MultiIndex slice using .loc (#37513)
1 parent d5bc5ae commit f646ea0

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

pandas/tests/indexing/test_loc.py

+18
Original file line numberDiff line numberDiff line change
@@ -1063,6 +1063,24 @@ def test_loc_getitem_access_none_value_in_multiindex(self):
10631063
result = ser.loc[("Level1", "Level2_a")]
10641064
assert result == 1
10651065

1066+
def test_loc_setitem_multiindex_slice(self):
1067+
# GH 34870
1068+
1069+
index = pd.MultiIndex.from_tuples(
1070+
zip(
1071+
["bar", "bar", "baz", "baz", "foo", "foo", "qux", "qux"],
1072+
["one", "two", "one", "two", "one", "two", "one", "two"],
1073+
),
1074+
names=["first", "second"],
1075+
)
1076+
1077+
result = Series([1, 1, 1, 1, 1, 1, 1, 1], index=index)
1078+
result.loc[("baz", "one"):("foo", "two")] = 100
1079+
1080+
expected = Series([1, 1, 100, 100, 100, 100, 1, 1], index=index)
1081+
1082+
tm.assert_series_equal(result, expected)
1083+
10661084

10671085
def test_series_loc_getitem_label_list_missing_values():
10681086
# gh-11428

0 commit comments

Comments
 (0)