Skip to content

Commit 8467b57

Browse files
committed
Tests for previous commit
1 parent 17209f3 commit 8467b57

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

pandas/tests/indexing/test_multiindex.py

+29
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,35 @@ def test_loc_getitem_series(self):
169169
result = x.loc[empty]
170170
tm.assert_series_equal(result, expected)
171171

172+
def test_loc_getitem_array(self):
173+
# GH15434
174+
# passing an array as a key with a MultiIndex
175+
index = MultiIndex.from_product([[1, 2, 3], ['A', 'B', 'C']])
176+
x = Series(index=index, data=range(9), dtype=np.float64)
177+
y = np.array([1, 3])
178+
expected = Series(
179+
data=[0, 1, 2, 6, 7, 8],
180+
index=MultiIndex.from_product([[1, 3], ['A', 'B', 'C']]),
181+
dtype=np.float64)
182+
result = x.loc[y]
183+
tm.assert_series_equal(result, expected)
184+
185+
# empty array:
186+
empty = np.array([])
187+
expected = Series([], index=MultiIndex(
188+
levels=index.levels, labels=[[], []], dtype=np.float64))
189+
result = x.loc[empty]
190+
tm.assert_series_equal(result, expected)
191+
192+
# 0-dim array (scalar):
193+
scalar = np.int64(1)
194+
expected = Series(
195+
data=[0, 1, 2],
196+
index=['A', 'B', 'C'],
197+
dtype=np.float64)
198+
result = x.loc[scalar]
199+
tm.assert_series_equal(result, expected)
200+
172201
def test_iloc_getitem_multiindex(self):
173202
mi_labels = DataFrame(np.random.randn(4, 3),
174203
columns=[['i', 'i', 'j'], ['A', 'A', 'B']],

0 commit comments

Comments
 (0)