@@ -37,7 +37,7 @@ def verify_pickle(self, indices):
37
37
def test_pickle_compat_construction (self ):
38
38
# this is testing for pickle compat
39
39
if self ._holder is None :
40
- return
40
+ pytest . skip ( 'Skip check for uncertain type' )
41
41
42
42
# need an object to create with
43
43
pytest .raises (TypeError , self ._holder )
@@ -236,7 +236,7 @@ def test_set_name_methods(self, indices):
236
236
237
237
# don't tests a MultiIndex here (as its tested separated)
238
238
if isinstance (indices , MultiIndex ):
239
- return
239
+ pytest . skip ( 'Skip check for MultiIndex' )
240
240
original_name = indices .name
241
241
new_ind = indices .set_names ([new_name ])
242
242
assert new_ind .name == new_name
@@ -333,7 +333,8 @@ def test_copy_and_deepcopy(self, indices):
333
333
from copy import copy , deepcopy
334
334
335
335
if isinstance (indices , MultiIndex ):
336
- return
336
+ pytest .skip ('Skip check for MultiIndex' )
337
+
337
338
for func in (copy , deepcopy ):
338
339
idx_copy = func (indices )
339
340
assert idx_copy is not indices
@@ -344,18 +345,46 @@ def test_copy_and_deepcopy(self, indices):
344
345
345
346
def test_duplicates (self , indices ):
346
347
if type (indices ) is not self ._holder :
347
- return
348
+ pytest . skip ( 'Can only check if we have the correct type' )
348
349
if not len (indices ) or isinstance (indices , MultiIndex ):
349
- return
350
+ # MultiIndex tested separately in:
351
+ # tests/indexes/multi/test_unique_and_duplicates
352
+ pytest .skip ('Skip check for empty Index and MultiIndex' )
353
+
350
354
idx = self ._holder ([indices [0 ]] * 5 )
351
355
assert not idx .is_unique
352
356
assert idx .has_duplicates
353
357
358
+ @pytest .mark .parametrize ('keep' , ['first' , 'last' , False ])
359
+ def test_duplicated (self , indices , keep ):
360
+ if type (indices ) is not self ._holder :
361
+ pytest .skip ('Can only check if we know the index type' )
362
+ if not len (indices ) or isinstance (indices , MultiIndex ):
363
+ # MultiIndex tested separately in:
364
+ # tests/indexes/multi/test_unique_and_duplicates
365
+ pytest .skip ('Skip check for empty Index and MultiIndex' )
366
+
367
+ idx = self ._holder (indices )
368
+ if idx .has_duplicates :
369
+ # We need to be able to control creation of duplicates here
370
+ # This is slightly circular, as drop_duplicates depends on
371
+ # duplicated, but in the end, it all works out because we
372
+ # cross-check with Series.duplicated
373
+ idx = idx .drop_duplicates ()
374
+
375
+ n , k = len (idx ), 10
376
+ duplicated_selection = np .random .choice (n , k * n )
377
+ expected = pd .Series (duplicated_selection ).duplicated (keep = keep ).values
378
+ idx = self ._holder (idx .values [duplicated_selection ])
379
+
380
+ result = idx .duplicated (keep = keep )
381
+ tm .assert_numpy_array_equal (result , expected )
382
+
354
383
def test_unique (self , indices ):
355
384
# don't test a MultiIndex here (as its tested separated)
356
385
# don't test a CategoricalIndex because categories change (GH 18291)
357
386
if isinstance (indices , (MultiIndex , CategoricalIndex )):
358
- return
387
+ pytest . skip ( 'Skip check for MultiIndex/CategoricalIndex' )
359
388
360
389
# GH 17896
361
390
expected = indices .drop_duplicates ()
@@ -375,7 +404,7 @@ def test_unique_na(self):
375
404
def test_get_unique_index (self , indices ):
376
405
# MultiIndex tested separately
377
406
if not len (indices ) or isinstance (indices , MultiIndex ):
378
- return
407
+ pytest . skip ( 'Skip check for empty Index and MultiIndex' )
379
408
380
409
idx = indices [[0 ] * 5 ]
381
410
idx_unique = indices [[0 ]]
@@ -394,7 +423,7 @@ def test_get_unique_index(self, indices):
394
423
395
424
# nans:
396
425
if not indices ._can_hold_na :
397
- return
426
+ pytest . skip ( 'Skip na-check if index cannot hold na' )
398
427
399
428
if needs_i8_conversion (indices ):
400
429
vals = indices .asi8 [[0 ] * 5 ]
@@ -423,7 +452,7 @@ def test_sort(self, indices):
423
452
424
453
def test_mutability (self , indices ):
425
454
if not len (indices ):
426
- return
455
+ pytest . skip ( 'Skip check for empty Index' )
427
456
pytest .raises (TypeError , indices .__setitem__ , 0 , indices [0 ])
428
457
429
458
def test_view (self , indices ):
@@ -761,7 +790,7 @@ def test_equals_op(self):
761
790
# GH9947, GH10637
762
791
index_a = self .create_index ()
763
792
if isinstance (index_a , PeriodIndex ):
764
- return
793
+ pytest . skip ( 'Skip check for PeriodIndex' )
765
794
766
795
n = len (index_a )
767
796
index_b = index_a [0 :- 1 ]
@@ -989,11 +1018,11 @@ def test_searchsorted_monotonic(self, indices):
989
1018
# not implemented for tuple searches in MultiIndex
990
1019
# or Intervals searches in IntervalIndex
991
1020
if isinstance (indices , (MultiIndex , IntervalIndex )):
992
- return
1021
+ pytest . skip ( 'Skip check for MultiIndex/IntervalIndex' )
993
1022
994
1023
# nothing to test if the index is empty
995
1024
if indices .empty :
996
- return
1025
+ pytest . skip ( 'Skip check for empty Index' )
997
1026
value = indices [0 ]
998
1027
999
1028
# determine the expected results (handle dupes for 'right')
0 commit comments