@@ -147,29 +147,24 @@ def test_searchsorted(request, index_or_series_obj):
147
147
# See gh-12238
148
148
obj = index_or_series_obj
149
149
150
- # 1. Check for multi-index
150
+ if any (isinstance (x , str ) for x in obj ) and any (isinstance (x , int ) for x in obj ):
151
+ request .applymarker (
152
+ pytest .mark .xfail (reason = "Cannot compare mixed types (str and int)" )
153
+ )
154
+
151
155
if isinstance (obj , pd .MultiIndex ):
152
- request .applymarker (pytest .mark .xfail (reason = "GH 14833" , strict = False ))
153
- return
154
-
155
- # 2. Check for Index and subtypes
156
- if isinstance (obj , Index ):
157
- # 2a. Mixed types
158
- if obj .inferred_type in ["mixed" , "mixed-integer" ]:
159
- try :
160
- obj = obj .astype (str )
161
- except (TypeError , ValueError ):
162
- request .applymarker (
163
- pytest .mark .xfail (reason = "Mixed types" , strict = False )
164
- )
165
- return
166
-
167
- # 2b. Complex types
168
- elif obj .dtype .kind == "c" :
169
- request .applymarker (pytest .mark .xfail (reason = "Complex types" , strict = False ))
170
- return
171
-
172
- # 3. Run test ONLY if there isn't mixed/complex types
156
+ # See gh-14833
157
+ request .applymarker (
158
+ pytest .mark .xfail (
159
+ reason = "np.searchsorted doesn't work on pd.MultiIndex: GH 14833"
160
+ )
161
+ )
162
+ elif obj .dtype .kind == "c" and isinstance (obj , Index ):
163
+ # TODO: Should Series cases also raise? Looks like they use numpy
164
+ # comparison semantics https://github.com/numpy/numpy/issues/15981
165
+ mark = pytest .mark .xfail (reason = "complex objects are not comparable" )
166
+ request .applymarker (mark )
167
+
173
168
max_obj = max (obj , default = 0 )
174
169
index = np .searchsorted (obj , max_obj )
175
170
assert 0 <= index <= len (obj )
0 commit comments