From 7e08a95ac457b8dc3284d45ffcf853f413f086a4 Mon Sep 17 00:00:00 2001 From: arw2019 Date: Fri, 30 Oct 2020 03:34:02 +0000 Subject: [PATCH 1/2] TST: add test from OP --- pandas/tests/indexing/test_loc.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/pandas/tests/indexing/test_loc.py b/pandas/tests/indexing/test_loc.py index 8fb418ab78307..05683170e25c9 100644 --- a/pandas/tests/indexing/test_loc.py +++ b/pandas/tests/indexing/test_loc.py @@ -1062,6 +1062,24 @@ def test_loc_getitem_access_none_value_in_multiindex(self): result = ser.loc[("Level1", "Level2_a")] assert result == 1 + def test_loc_setitem_multiindex_slice(self): + # GH 34870 + + index = pd.MultiIndex.from_tuples( + zip( + ["bar", "bar", "baz", "baz", "foo", "foo", "qux", "qux"], + ["one", "two", "one", "two", "one", "two", "one", "two"], + ), + names=["first", "second"], + ) + + result = pd.Series([1, 1, 1, 1, 1, 1, 1, 1], index=index) + result.loc[("baz", "one"):("foo", "two")] = 100 + + expected = pd.Series([1, 1, 100, 100, 100, 100, 1, 1], index=index) + + tm.assert_series_equal(result, expected) + def test_series_loc_getitem_label_list_missing_values(): # gh-11428 From 4be231ad39d917b094f99739e039ac0bf6492403 Mon Sep 17 00:00:00 2001 From: arw2019 Date: Fri, 30 Oct 2020 05:33:03 +0000 Subject: [PATCH 2/2] CI: fix inconsistent usage of pd namespace --- pandas/tests/indexing/test_loc.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/tests/indexing/test_loc.py b/pandas/tests/indexing/test_loc.py index 05683170e25c9..eb84f771204f6 100644 --- a/pandas/tests/indexing/test_loc.py +++ b/pandas/tests/indexing/test_loc.py @@ -1073,10 +1073,10 @@ def test_loc_setitem_multiindex_slice(self): names=["first", "second"], ) - result = pd.Series([1, 1, 1, 1, 1, 1, 1, 1], index=index) + result = Series([1, 1, 1, 1, 1, 1, 1, 1], index=index) result.loc[("baz", "one"):("foo", "two")] = 100 - expected = pd.Series([1, 1, 100, 100, 100, 100, 1, 1], index=index) + expected = Series([1, 1, 100, 100, 100, 100, 1, 1], index=index) tm.assert_series_equal(result, expected)