@@ -363,6 +363,7 @@ def test_numpy_argsort(self, index):
363
363
# cannot be changed at the moment due to
364
364
# backwards compatibility concerns
365
365
if isinstance (type (index ), (CategoricalIndex , RangeIndex )):
366
+ # TODO: why type(index)?
366
367
msg = "the 'axis' parameter is not supported"
367
368
with pytest .raises (ValueError , match = msg ):
368
369
np .argsort (index , axis = 1 )
@@ -375,49 +376,6 @@ def test_numpy_argsort(self, index):
375
376
with pytest .raises (ValueError , match = msg ):
376
377
np .argsort (index , order = ("a" , "b" ))
377
378
378
- def test_take (self , index ):
379
- indexer = [4 , 3 , 0 , 2 ]
380
- if len (index ) < 5 :
381
- # not enough elements; ignore
382
- return
383
-
384
- result = index .take (indexer )
385
- expected = index [indexer ]
386
- assert result .equals (expected )
387
-
388
- if not isinstance (index , (DatetimeIndex , PeriodIndex , TimedeltaIndex )):
389
- # GH 10791
390
- msg = r"'(.*Index)' object has no attribute 'freq'"
391
- with pytest .raises (AttributeError , match = msg ):
392
- index .freq
393
-
394
- def test_take_invalid_kwargs (self ):
395
- idx = self .create_index ()
396
- indices = [1 , 2 ]
397
-
398
- msg = r"take\(\) got an unexpected keyword argument 'foo'"
399
- with pytest .raises (TypeError , match = msg ):
400
- idx .take (indices , foo = 2 )
401
-
402
- msg = "the 'out' parameter is not supported"
403
- with pytest .raises (ValueError , match = msg ):
404
- idx .take (indices , out = indices )
405
-
406
- msg = "the 'mode' parameter is not supported"
407
- with pytest .raises (ValueError , match = msg ):
408
- idx .take (indices , mode = "clip" )
409
-
410
- def test_take_minus1_without_fill (self , index ):
411
- # -1 does not get treated as NA unless allow_fill=True is passed
412
- if len (index ) == 0 :
413
- # Test is not applicable
414
- return
415
-
416
- result = index .take ([0 , 0 , - 1 ])
417
-
418
- expected = index .take ([0 , 0 , len (index ) - 1 ])
419
- tm .assert_index_equal (result , expected )
420
-
421
379
def test_repeat (self ):
422
380
rep = 2
423
381
i = self .create_index ()
@@ -456,117 +414,6 @@ def test_where(self, klass):
456
414
result = i .where (klass (cond ))
457
415
tm .assert_index_equal (result , expected )
458
416
459
- @pytest .mark .parametrize ("case" , [0.5 , "xxx" ])
460
- @pytest .mark .parametrize (
461
- "method" , ["intersection" , "union" , "difference" , "symmetric_difference" ]
462
- )
463
- def test_set_ops_error_cases (self , case , method , index ):
464
- # non-iterable input
465
- msg = "Input must be Index or array-like"
466
- with pytest .raises (TypeError , match = msg ):
467
- getattr (index , method )(case )
468
-
469
- def test_intersection_base (self , index ):
470
- if isinstance (index , CategoricalIndex ):
471
- return
472
-
473
- first = index [:5 ]
474
- second = index [:3 ]
475
- intersect = first .intersection (second )
476
- assert tm .equalContents (intersect , second )
477
-
478
- if is_datetime64tz_dtype (index .dtype ):
479
- # The second.values below will drop tz, so the rest of this test
480
- # is not applicable.
481
- return
482
-
483
- # GH 10149
484
- cases = [klass (second .values ) for klass in [np .array , Series , list ]]
485
- for case in cases :
486
- result = first .intersection (case )
487
- assert tm .equalContents (result , second )
488
-
489
- if isinstance (index , MultiIndex ):
490
- msg = "other must be a MultiIndex or a list of tuples"
491
- with pytest .raises (TypeError , match = msg ):
492
- first .intersection ([1 , 2 , 3 ])
493
-
494
- def test_union_base (self , index ):
495
- first = index [3 :]
496
- second = index [:5 ]
497
- everything = index
498
- union = first .union (second )
499
- assert tm .equalContents (union , everything )
500
-
501
- if is_datetime64tz_dtype (index .dtype ):
502
- # The second.values below will drop tz, so the rest of this test
503
- # is not applicable.
504
- return
505
-
506
- # GH 10149
507
- cases = [klass (second .values ) for klass in [np .array , Series , list ]]
508
- for case in cases :
509
- if not isinstance (index , CategoricalIndex ):
510
- result = first .union (case )
511
- assert tm .equalContents (result , everything ), (
512
- result ,
513
- everything ,
514
- type (case ),
515
- )
516
-
517
- if isinstance (index , MultiIndex ):
518
- msg = "other must be a MultiIndex or a list of tuples"
519
- with pytest .raises (TypeError , match = msg ):
520
- first .union ([1 , 2 , 3 ])
521
-
522
- def test_difference_base (self , sort , index ):
523
- first = index [2 :]
524
- second = index [:4 ]
525
- if isinstance (index , CategoricalIndex ) or index .is_boolean ():
526
- answer = []
527
- else :
528
- answer = index [4 :]
529
- result = first .difference (second , sort )
530
- assert tm .equalContents (result , answer )
531
-
532
- # GH 10149
533
- cases = [klass (second .values ) for klass in [np .array , Series , list ]]
534
- for case in cases :
535
- if isinstance (index , (DatetimeIndex , TimedeltaIndex )):
536
- assert type (result ) == type (answer )
537
- tm .assert_numpy_array_equal (
538
- result .sort_values ().asi8 , answer .sort_values ().asi8
539
- )
540
- else :
541
- result = first .difference (case , sort )
542
- assert tm .equalContents (result , answer )
543
-
544
- if isinstance (index , MultiIndex ):
545
- msg = "other must be a MultiIndex or a list of tuples"
546
- with pytest .raises (TypeError , match = msg ):
547
- first .difference ([1 , 2 , 3 ], sort )
548
-
549
- def test_symmetric_difference (self , index ):
550
- if isinstance (index , CategoricalIndex ):
551
- return
552
-
553
- first = index [1 :]
554
- second = index [:- 1 ]
555
- answer = index [[0 , - 1 ]]
556
- result = first .symmetric_difference (second )
557
- assert tm .equalContents (result , answer )
558
-
559
- # GH 10149
560
- cases = [klass (second .values ) for klass in [np .array , Series , list ]]
561
- for case in cases :
562
- result = first .symmetric_difference (case )
563
- assert tm .equalContents (result , answer )
564
-
565
- if isinstance (index , MultiIndex ):
566
- msg = "other must be a MultiIndex or a list of tuples"
567
- with pytest .raises (TypeError , match = msg ):
568
- first .symmetric_difference ([1 , 2 , 3 ])
569
-
570
417
def test_insert_base (self , index ):
571
418
result = index [1 :4 ]
572
419
@@ -601,7 +448,8 @@ def test_delete_base(self, index):
601
448
602
449
def test_equals (self , index ):
603
450
if isinstance (index , IntervalIndex ):
604
- # IntervalIndex tested separately
451
+ # IntervalIndex tested separately, the index.equals(index.astype(object))
452
+ # fails for IntervalIndex
605
453
return
606
454
607
455
assert index .equals (index )
0 commit comments