Skip to content

Commit d2e767b

Browse files
committed
TST: tests for indexing MultiIndex with generator
1 parent 95d1c6b commit d2e767b

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

pandas/tests/indexing/test_multiindex.py

+21
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,27 @@ def test_loc_getitem_array(self):
203203
result = x.loc[scalar]
204204
tm.assert_series_equal(result, expected)
205205

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

0 commit comments

Comments
 (0)