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