@@ -37,7 +37,7 @@ def verify_pickle(self, indices):
3737 def test_pickle_compat_construction (self ):
3838 # this is testing for pickle compat
3939 if self ._holder is None :
40- return
40+ pytest . skip ( 'Skip check for uncertain type' )
4141
4242 # need an object to create with
4343 pytest .raises (TypeError , self ._holder )
@@ -236,7 +236,7 @@ def test_set_name_methods(self, indices):
236236
237237 # don't tests a MultiIndex here (as its tested separated)
238238 if isinstance (indices , MultiIndex ):
239- return
239+ pytest . skip ( 'Skip check for MultiIndex' )
240240 original_name = indices .name
241241 new_ind = indices .set_names ([new_name ])
242242 assert new_ind .name == new_name
@@ -333,7 +333,8 @@ def test_copy_and_deepcopy(self, indices):
333333 from copy import copy , deepcopy
334334
335335 if isinstance (indices , MultiIndex ):
336- return
336+ pytest .skip ('Skip check for MultiIndex' )
337+
337338 for func in (copy , deepcopy ):
338339 idx_copy = func (indices )
339340 assert idx_copy is not indices
@@ -344,18 +345,46 @@ def test_copy_and_deepcopy(self, indices):
344345
345346 def test_duplicates (self , indices ):
346347 if type (indices ) is not self ._holder :
347- return
348+ pytest . skip ( 'Can only check if we have the correct type' )
348349 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+
350354 idx = self ._holder ([indices [0 ]] * 5 )
351355 assert not idx .is_unique
352356 assert idx .has_duplicates
353357
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+
354383 def test_unique (self , indices ):
355384 # don't test a MultiIndex here (as its tested separated)
356385 # don't test a CategoricalIndex because categories change (GH 18291)
357386 if isinstance (indices , (MultiIndex , CategoricalIndex )):
358- return
387+ pytest . skip ( 'Skip check for MultiIndex/CategoricalIndex' )
359388
360389 # GH 17896
361390 expected = indices .drop_duplicates ()
@@ -375,7 +404,7 @@ def test_unique_na(self):
375404 def test_get_unique_index (self , indices ):
376405 # MultiIndex tested separately
377406 if not len (indices ) or isinstance (indices , MultiIndex ):
378- return
407+ pytest . skip ( 'Skip check for empty Index and MultiIndex' )
379408
380409 idx = indices [[0 ] * 5 ]
381410 idx_unique = indices [[0 ]]
@@ -394,7 +423,7 @@ def test_get_unique_index(self, indices):
394423
395424 # nans:
396425 if not indices ._can_hold_na :
397- return
426+ pytest . skip ( 'Skip na-check if index cannot hold na' )
398427
399428 if needs_i8_conversion (indices ):
400429 vals = indices .asi8 [[0 ] * 5 ]
@@ -423,7 +452,7 @@ def test_sort(self, indices):
423452
424453 def test_mutability (self , indices ):
425454 if not len (indices ):
426- return
455+ pytest . skip ( 'Skip check for empty Index' )
427456 pytest .raises (TypeError , indices .__setitem__ , 0 , indices [0 ])
428457
429458 def test_view (self , indices ):
@@ -761,7 +790,7 @@ def test_equals_op(self):
761790 # GH9947, GH10637
762791 index_a = self .create_index ()
763792 if isinstance (index_a , PeriodIndex ):
764- return
793+ pytest . skip ( 'Skip check for PeriodIndex' )
765794
766795 n = len (index_a )
767796 index_b = index_a [0 :- 1 ]
@@ -989,11 +1018,11 @@ def test_searchsorted_monotonic(self, indices):
9891018 # not implemented for tuple searches in MultiIndex
9901019 # or Intervals searches in IntervalIndex
9911020 if isinstance (indices , (MultiIndex , IntervalIndex )):
992- return
1021+ pytest . skip ( 'Skip check for MultiIndex/IntervalIndex' )
9931022
9941023 # nothing to test if the index is empty
9951024 if indices .empty :
996- return
1025+ pytest . skip ( 'Skip check for empty Index' )
9971026 value = indices [0 ]
9981027
9991028 # determine the expected results (handle dupes for 'right')
0 commit comments