@@ -189,14 +189,17 @@ def test_get_indexer_and_fill():
189
189
mult_idx_2 = MultiIndex .from_product ([[0 ], [1 , 3 , 4 ]])
190
190
191
191
tm .assert_almost_equal (mult_idx_1 .get_indexer (mult_idx_2 ), np .array ([- 1 , 2 , 3 ]))
192
- tm .assert_almost_equal (mult_idx_1 .get_indexer (mult_idx_2 , method = 'backfill' ),
193
- np .array ([1 , 2 , 3 ]))
192
+ tm .assert_almost_equal (
193
+ mult_idx_1 .get_indexer (mult_idx_2 , method = "backfill" ), np .array ([1 , 2 , 3 ])
194
+ )
194
195
for method in ("bfill" , "backfill" ):
195
- tm .assert_almost_equal (mult_idx_1 .get_indexer (mult_idx_2 , method = method ),
196
- np .array ([1 , 2 , 3 ]))
196
+ tm .assert_almost_equal (
197
+ mult_idx_1 .get_indexer (mult_idx_2 , method = method ), np .array ([1 , 2 , 3 ])
198
+ )
197
199
for method in ("ffill" , "pad" ):
198
- tm .assert_almost_equal (mult_idx_1 .get_indexer (mult_idx_2 , method = method ),
199
- np .array ([0 , 2 , 3 ]))
200
+ tm .assert_almost_equal (
201
+ mult_idx_1 .get_indexer (mult_idx_2 , method = method ), np .array ([0 , 2 , 3 ])
202
+ )
200
203
201
204
202
205
def test_get_indexer_three_or_more_levels ():
@@ -228,13 +231,9 @@ def test_get_indexer_three_or_more_levels():
228
231
6: 3 6 8
229
232
"""
230
233
mult_idx_1 = pd .MultiIndex .from_product ([[1 , 3 ], [2 , 4 , 6 ], [5 , 7 ]])
231
- mult_idx_2 = pd .MultiIndex .from_tuples ([(1 , 1 , 8 ),
232
- (1 , 5 , 9 ),
233
- (1 , 6 , 7 ),
234
- (2 , 1 , 6 ),
235
- (2 , 7 , 7 ),
236
- (2 , 7 , 8 ),
237
- (3 , 6 , 8 )])
234
+ mult_idx_2 = pd .MultiIndex .from_tuples (
235
+ [(1 , 1 , 8 ), (1 , 5 , 9 ), (1 , 6 , 7 ), (2 , 1 , 6 ), (2 , 7 , 7 ), (2 , 7 , 8 ), (3 , 6 , 8 )]
236
+ )
238
237
# sanity check
239
238
assert mult_idx_1 .is_monotonic
240
239
assert mult_idx_1 .is_unique
@@ -251,18 +250,15 @@ def test_get_indexer_three_or_more_levels():
251
250
assert mult_idx_1 [- 1 ] < mult_idx_2 [6 ]
252
251
253
252
indexer_no_fill = mult_idx_1 .get_indexer (mult_idx_2 )
254
- tm .assert_almost_equal (indexer_no_fill ,
255
- np .array ([- 1 , - 1 , 5 , - 1 , - 1 , - 1 , - 1 ]))
253
+ tm .assert_almost_equal (indexer_no_fill , np .array ([- 1 , - 1 , 5 , - 1 , - 1 , - 1 , - 1 ]))
256
254
257
255
# test with backfilling
258
- indexer_backfilled = mult_idx_1 .get_indexer (mult_idx_2 , method = 'backfill' )
259
- tm . assert_almost_equal (indexer_backfilled ,
260
- np .array ([0 , 4 , 5 , 6 , 6 , 6 , - 1 ]))
256
+ indexer_backfilled = mult_idx_1 .get_indexer (mult_idx_2 , method = "backfill" )
257
+ tm .assert_almost_equal (indexer_backfilled , np .array ([0 , 4 , 5 , 6 , 6 , 6 , - 1 ]))
261
258
262
259
# now, the same thing, but forward-filled (aka "padded")
263
- indexer_padded = mult_idx_1 .get_indexer (mult_idx_2 , method = 'pad' )
264
- tm .assert_almost_equal (indexer_padded ,
265
- np .array ([- 1 , 3 , 5 , 5 , 5 , 5 , 11 ]))
260
+ indexer_padded = mult_idx_1 .get_indexer (mult_idx_2 , method = "pad" )
261
+ tm .assert_almost_equal (indexer_padded , np .array ([- 1 , 3 , 5 , 5 , 5 , 5 , 11 ]))
266
262
267
263
# now, do the indexing in the other direction
268
264
assert mult_idx_2 [0 ] < mult_idx_1 [0 ] < mult_idx_2 [1 ]
@@ -278,21 +274,18 @@ def test_get_indexer_three_or_more_levels():
278
274
assert mult_idx_2 [5 ] < mult_idx_1 [10 ] < mult_idx_2 [6 ]
279
275
assert mult_idx_2 [5 ] < mult_idx_1 [11 ] < mult_idx_2 [6 ]
280
276
281
- tm .assert_almost_equal (mult_idx_2 .get_indexer (mult_idx_1 ),
282
- np .array ([
283
- - 1 , - 1 , - 1 , - 1 , - 1 , 2 ,
284
- - 1 , - 1 , - 1 , - 1 , - 1 , - 1 ,
285
- ]))
286
- tm .assert_almost_equal (mult_idx_2 .get_indexer (mult_idx_1 , method = 'bfill' ),
287
- np .array ([
288
- 1 , 1 , 1 , 1 , 2 , 2 ,
289
- 6 , 6 , 6 , 6 , 6 , 6 ,
290
- ]))
291
- tm .assert_almost_equal (mult_idx_2 .get_indexer (mult_idx_1 , method = 'pad' ),
292
- np .array ([
293
- 0 , 0 , 0 , 0 , 1 , 2 ,
294
- 5 , 5 , 5 , 5 , 5 , 5 ,
295
- ]))
277
+ tm .assert_almost_equal (
278
+ mult_idx_2 .get_indexer (mult_idx_1 ),
279
+ np .array ([- 1 , - 1 , - 1 , - 1 , - 1 , 2 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 ,]),
280
+ )
281
+ tm .assert_almost_equal (
282
+ mult_idx_2 .get_indexer (mult_idx_1 , method = "bfill" ),
283
+ np .array ([1 , 1 , 1 , 1 , 2 , 2 , 6 , 6 , 6 , 6 , 6 , 6 ,]),
284
+ )
285
+ tm .assert_almost_equal (
286
+ mult_idx_2 .get_indexer (mult_idx_1 , method = "pad" ),
287
+ np .array ([0 , 0 , 0 , 0 , 1 , 2 , 5 , 5 , 5 , 5 , 5 , 5 ,]),
288
+ )
296
289
297
290
298
291
def test_get_indexer_backfill_with_carrying ():
@@ -330,12 +323,13 @@ def test_get_indexer_backfill_with_carrying():
330
323
assert mult_idx_1 [7 ] < mult_idx_2 [0 ] < mult_idx_1 [8 ]
331
324
assert mult_idx_1 [- 1 ] < mult_idx_2 [1 ]
332
325
333
- tm .assert_almost_equal (mult_idx_1 .get_indexer (mult_idx_2 ),
334
- np .array ([- 1 , - 1 ]))
335
- tm .assert_almost_equal (mult_idx_1 .get_indexer (mult_idx_2 , method = 'bfill' ),
336
- np .array ([8 , - 1 ]))
337
- tm .assert_almost_equal (mult_idx_1 .get_indexer (mult_idx_2 , method = 'ffill' ),
338
- np .array ([7 , 15 ]))
326
+ tm .assert_almost_equal (mult_idx_1 .get_indexer (mult_idx_2 ), np .array ([- 1 , - 1 ]))
327
+ tm .assert_almost_equal (
328
+ mult_idx_1 .get_indexer (mult_idx_2 , method = "bfill" ), np .array ([8 , - 1 ])
329
+ )
330
+ tm .assert_almost_equal (
331
+ mult_idx_1 .get_indexer (mult_idx_2 , method = "ffill" ), np .array ([7 , 15 ])
332
+ )
339
333
340
334
341
335
def test_get_indexer_nearest ():
0 commit comments