@@ -169,6 +169,35 @@ def test_loc_getitem_series(self):
169
169
result = x .loc [empty ]
170
170
tm .assert_series_equal (result , expected )
171
171
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
+
172
201
def test_iloc_getitem_multiindex (self ):
173
202
mi_labels = DataFrame (np .random .randn (4 , 3 ),
174
203
columns = [['i' , 'i' , 'j' ], ['A' , 'A' , 'B' ]],
0 commit comments