Skip to content

Commit bafec32

Browse files
committed
TST: tests for indexing MultiIndex with generator
1 parent 7afe82c commit bafec32

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

pandas/tests/indexing/test_multiindex.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,27 @@ def test_loc_getitem_array(self):
198198
result = x.loc[scalar]
199199
tm.assert_series_equal(result, expected)
200200

201+
def test_loc_generator(self):
202+
index = MultiIndex.from_product([[1, 2, 3], ['A', 'B', 'C']])
203+
x = Series(index=index, data=range(9), dtype=np.float64)
204+
y = [1, 3]
205+
206+
# getitem:
207+
expected = Series(
208+
data=[0, 1, 2, 6, 7, 8],
209+
index=MultiIndex.from_product([[1, 3], ['A', 'B', 'C']]),
210+
dtype=np.float64)
211+
result = x.loc[iter(y)]
212+
tm.assert_series_equal(result, expected)
213+
214+
# setitem:
215+
expected = Series(
216+
data=[9, 10, 11, 3, 4, 5, 12, 13, 14],
217+
index=index,
218+
dtype=np.float64)
219+
x.loc[iter(y)] = range(9, 15)
220+
tm.assert_series_equal(x, expected)
221+
201222
def test_iloc_getitem_multiindex(self):
202223
mi_labels = DataFrame(np.random.randn(4, 3),
203224
columns=[['i', 'i', 'j'], ['A', 'A', 'B']],

0 commit comments

Comments
 (0)