@@ -410,89 +410,6 @@ def test_sort_values(self):
410
410
assert ordered [::- 1 ].is_monotonic
411
411
tm .assert_numpy_array_equal (dexer , np .array ([0 , 2 , 1 ], dtype = np .intp ))
412
412
413
- def test_take (self ):
414
- dates = [datetime (2010 , 1 , 1 , 14 ), datetime (2010 , 1 , 1 , 15 ),
415
- datetime (2010 , 1 , 1 , 17 ), datetime (2010 , 1 , 1 , 21 )]
416
-
417
- for tz in [None , 'US/Eastern' , 'Asia/Tokyo' ]:
418
- idx = DatetimeIndex (start = '2010-01-01 09:00' ,
419
- end = '2010-02-01 09:00' , freq = 'H' , tz = tz ,
420
- name = 'idx' )
421
- expected = DatetimeIndex (dates , freq = None , name = 'idx' , tz = tz )
422
-
423
- taken1 = idx .take ([5 , 6 , 8 , 12 ])
424
- taken2 = idx [[5 , 6 , 8 , 12 ]]
425
-
426
- for taken in [taken1 , taken2 ]:
427
- tm .assert_index_equal (taken , expected )
428
- assert isinstance (taken , DatetimeIndex )
429
- assert taken .freq is None
430
- assert taken .tz == expected .tz
431
- assert taken .name == expected .name
432
-
433
- def test_take_fill_value (self ):
434
- # GH 12631
435
- idx = pd .DatetimeIndex (['2011-01-01' , '2011-02-01' , '2011-03-01' ],
436
- name = 'xxx' )
437
- result = idx .take (np .array ([1 , 0 , - 1 ]))
438
- expected = pd .DatetimeIndex (['2011-02-01' , '2011-01-01' , '2011-03-01' ],
439
- name = 'xxx' )
440
- tm .assert_index_equal (result , expected )
441
-
442
- # fill_value
443
- result = idx .take (np .array ([1 , 0 , - 1 ]), fill_value = True )
444
- expected = pd .DatetimeIndex (['2011-02-01' , '2011-01-01' , 'NaT' ],
445
- name = 'xxx' )
446
- tm .assert_index_equal (result , expected )
447
-
448
- # allow_fill=False
449
- result = idx .take (np .array ([1 , 0 , - 1 ]), allow_fill = False ,
450
- fill_value = True )
451
- expected = pd .DatetimeIndex (['2011-02-01' , '2011-01-01' , '2011-03-01' ],
452
- name = 'xxx' )
453
- tm .assert_index_equal (result , expected )
454
-
455
- msg = ('When allow_fill=True and fill_value is not None, '
456
- 'all indices must be >= -1' )
457
- with tm .assert_raises_regex (ValueError , msg ):
458
- idx .take (np .array ([1 , 0 , - 2 ]), fill_value = True )
459
- with tm .assert_raises_regex (ValueError , msg ):
460
- idx .take (np .array ([1 , 0 , - 5 ]), fill_value = True )
461
-
462
- with pytest .raises (IndexError ):
463
- idx .take (np .array ([1 , - 5 ]))
464
-
465
- def test_take_fill_value_with_timezone (self ):
466
- idx = pd .DatetimeIndex (['2011-01-01' , '2011-02-01' , '2011-03-01' ],
467
- name = 'xxx' , tz = 'US/Eastern' )
468
- result = idx .take (np .array ([1 , 0 , - 1 ]))
469
- expected = pd .DatetimeIndex (['2011-02-01' , '2011-01-01' , '2011-03-01' ],
470
- name = 'xxx' , tz = 'US/Eastern' )
471
- tm .assert_index_equal (result , expected )
472
-
473
- # fill_value
474
- result = idx .take (np .array ([1 , 0 , - 1 ]), fill_value = True )
475
- expected = pd .DatetimeIndex (['2011-02-01' , '2011-01-01' , 'NaT' ],
476
- name = 'xxx' , tz = 'US/Eastern' )
477
- tm .assert_index_equal (result , expected )
478
-
479
- # allow_fill=False
480
- result = idx .take (np .array ([1 , 0 , - 1 ]), allow_fill = False ,
481
- fill_value = True )
482
- expected = pd .DatetimeIndex (['2011-02-01' , '2011-01-01' , '2011-03-01' ],
483
- name = 'xxx' , tz = 'US/Eastern' )
484
- tm .assert_index_equal (result , expected )
485
-
486
- msg = ('When allow_fill=True and fill_value is not None, '
487
- 'all indices must be >= -1' )
488
- with tm .assert_raises_regex (ValueError , msg ):
489
- idx .take (np .array ([1 , 0 , - 2 ]), fill_value = True )
490
- with tm .assert_raises_regex (ValueError , msg ):
491
- idx .take (np .array ([1 , 0 , - 5 ]), fill_value = True )
492
-
493
- with pytest .raises (IndexError ):
494
- idx .take (np .array ([1 , - 5 ]))
495
-
496
413
def test_map_bug_1677 (self ):
497
414
index = DatetimeIndex (['2012-04-25 09:30:00.393000' ])
498
415
f = index .asof
0 commit comments