@@ -138,9 +138,10 @@ def test_get_indexer_consistency(self):
138
138
if isinstance (index , IntervalIndex ):
139
139
continue
140
140
141
- indexer = index .get_indexer (index [0 :2 ])
142
- assert isinstance (indexer , np .ndarray )
143
- assert indexer .dtype == np .intp
141
+ if index .is_unique :
142
+ indexer = index .get_indexer (index [0 :2 ])
143
+ assert isinstance (indexer , np .ndarray )
144
+ assert indexer .dtype == np .intp
144
145
145
146
indexer , _ = index .get_indexer_non_unique (index [0 :2 ])
146
147
assert isinstance (indexer , np .ndarray )
@@ -551,8 +552,6 @@ def test_setops_errorcases(self):
551
552
"or array-like" ,
552
553
method , case )
553
554
554
- @pytest .mark .xfail (reason = 'intersection fails for monotonic decreasing '
555
- 'RangeIndex (GH 17296)' )
556
555
def test_intersection_base (self ):
557
556
for name , idx in compat .iteritems (self .indices ):
558
557
first = idx [:5 ]
@@ -561,6 +560,9 @@ def test_intersection_base(self):
561
560
562
561
if isinstance (idx , CategoricalIndex ):
563
562
pass
563
+ elif isinstance (idx , RangeIndex ):
564
+ pytest .xfail (reason = 'intersection fails for decreasing '
565
+ 'RangeIndex (GH 17296)' )
564
566
else :
565
567
assert tm .equalContents (intersect , second )
566
568
@@ -971,9 +973,32 @@ def test_searchsorted_monotonic(self):
971
973
continue
972
974
value = index [0 ]
973
975
974
- if index .is_monotonic_increasing or index .is_monotonic_decreasing :
975
- assert index ._searchsorted_monotonic (value , side = 'left' ) == 0
976
- assert index ._searchsorted_monotonic (value , side = 'right' ) == 1
976
+ # determine the expected results (handle dupes for 'right')
977
+ expected_left , expected_right = 0 , (index == value ).argmin ()
978
+ if expected_right == 0 :
979
+ # all values are the same, expected_right should be length
980
+ expected_right = len (index )
981
+
982
+ # test _searchsorted_monotonic in all cases
983
+ # test searchsorted only for increasing
984
+ if index .is_monotonic_increasing :
985
+ ssm_left = index ._searchsorted_monotonic (value , side = 'left' )
986
+ assert expected_left == ssm_left
987
+
988
+ ssm_right = index ._searchsorted_monotonic (value , side = 'right' )
989
+ assert expected_right == ssm_right
990
+
991
+ ss_left = index .searchsorted (value , side = 'left' )
992
+ assert expected_left == ss_left
993
+
994
+ ss_right = index .searchsorted (value , side = 'right' )
995
+ assert expected_right == ss_right
996
+ elif index .is_monotonic_decreasing :
997
+ ssm_left = index ._searchsorted_monotonic (value , side = 'left' )
998
+ assert expected_left == ssm_left
999
+
1000
+ ssm_right = index ._searchsorted_monotonic (value , side = 'right' )
1001
+ assert expected_right == ssm_right
977
1002
else :
978
1003
# non-monotonic should raise.
979
1004
with pytest .raises (ValueError ):
0 commit comments