diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index b12a556a8291d..0f2fba741f7be 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -4947,6 +4947,7 @@ def slice_indexer(self, start=None, end=None, step=None, kind=None): start_slice, end_slice = self.slice_locs(start, end, step=step, kind=kind) # return a slice + if not is_scalar(start_slice): raise AssertionError("Start slice bound is non-scalar") if not is_scalar(end_slice): diff --git a/pandas/core/indexes/multi.py b/pandas/core/indexes/multi.py index 15db6c51a1f2f..4a062d22a13c5 100644 --- a/pandas/core/indexes/multi.py +++ b/pandas/core/indexes/multi.py @@ -2928,12 +2928,8 @@ def convert_indexer(start, stop, step, indexer=indexer, codes=level_codes): stop = len(level_index) - 1 step = key.step except KeyError: - - # we have a partial slice (like looking up a partial date - # string) - start = stop = level_index.slice_indexer( - key.start, key.stop, key.step, kind="loc" - ) + start = key.start + stop = key.stop step = start.step if isinstance(start, slice) or isinstance(stop, slice): diff --git a/pandas/tests/indexing/test_loc.py b/pandas/tests/indexing/test_loc.py index 47980e88f76d4..c1a37d46c9816 100644 --- a/pandas/tests/indexing/test_loc.py +++ b/pandas/tests/indexing/test_loc.py @@ -1119,3 +1119,22 @@ def test_loc_with_period_index_indexer(): tm.assert_frame_equal(df, df.loc[list(idx)]) tm.assert_frame_equal(df.iloc[0:5], df.loc[idx[0:5]]) tm.assert_frame_equal(df, df.loc[list(idx)]) + + +def test_loc_setting_value_at_multiindex(): + # GH 34870 + arrays = [ + ["bar", "bar", "baz", "baz", "foo", "foo", "qux", "qux"], + ["one", "two", "one", "two", "one", "two", "one", "two"], + ] + array = [1, 1, 1, 1, 1, 1, 1, 1] + answer = [1, 1, 100, 100, 100, 100, 1, 1] + + tuples = list(zip(*arrays)) + index = pd.MultiIndex.from_tuples(tuples, names=["first", "second"]) + + result = pd.Series(array, index=index) + expected = pd.Series(answer, index=index) + + result.loc[("baz", "one"):("foo", "two")] = 100 + tm.assert_series_equal(result, expected)