@@ -147,48 +147,25 @@ def test_searchsorted(request, index_or_series_obj):
147
147
# See gh-12238
148
148
obj = index_or_series_obj
149
149
150
- # Handle mixed int string
151
- if isinstance (obj , Index ) and obj .inferred_type in ["mixed" , "mixed-integer" ]:
152
- request .applymarker (
153
- pytest .mark .xfail (
154
- reason = "Cannot compare mixed types (str and int)" , strict = False
155
- )
156
- )
157
- obj = obj .unique ()
158
-
159
- # Mixed int string specific case
160
- if obj .equals (Index ([0 , "a" , 1 , "b" , 2 , "c" ])):
161
- obj = obj .astype (str )
162
-
150
+ # Check for MultiIndex
163
151
if isinstance (obj , pd .MultiIndex ):
164
- # See gh-14833
165
- request .applymarker (
166
- pytest .mark .xfail (
167
- reason = "np.searchsorted doesn't work on pd.MultiIndex: GH 14833" ,
168
- strict = False ,
169
- )
170
- )
171
- return
172
-
173
- if obj .dtype .kind == "c" and isinstance (obj , Index ):
174
- # Complex numbers are not comparable
175
- request .applymarker (
176
- pytest .mark .xfail (reason = "Complex objects are not comparable" , strict = False )
177
- )
178
- return
179
-
180
- if isinstance (obj , Index ) and obj .inferred_type == "tuples" :
181
- # Tuples may not be supported by np.searchsorted
182
- pytest .mark .xfail (reason = "Cannot handle tuples in searchsorted" , strict = False )
183
-
184
- # Only proceed if obj is not mixed or unsupported
185
- try :
186
- max_obj = max (obj , default = 0 )
187
- except TypeError :
188
- pytest .mark .xfail (
189
- reason = "Cannot compute max for unsupported types" , strict = False
190
- )
191
-
152
+ pytest .xfail ("np.searchsorted doesn't work on pd.MultiIndex: GH 14833" )
153
+
154
+ # Check for Index and subtypes
155
+ if isinstance (obj , Index ):
156
+ # Mixed types
157
+ if obj .inferred_type in ["mixed" , "mixed-integer" ]:
158
+ try :
159
+ obj = obj .astype (str )
160
+ except (TypeError , ValueError ):
161
+ pytest .xfail ("Cannot compare mixed types (str and int)" )
162
+
163
+ # Complex types
164
+ elif obj .dtype .kind == "c" :
165
+ pytest .xfail ("Complex objects are not comparable" )
166
+
167
+ # Run tests
168
+ max_obj = max (obj , default = 0 )
192
169
index = np .searchsorted (obj , max_obj )
193
170
assert 0 <= index <= len (obj )
194
171
0 commit comments