Skip to content

Commit 7d13666

Browse files
committed
test_misc
1 parent 4301c3f commit 7d13666

File tree

1 file changed

+31
-9
lines changed

1 file changed

+31
-9
lines changed

pandas/tests/base/test_misc.py

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -147,25 +147,47 @@ def test_searchsorted(request, index_or_series_obj):
147147
# See gh-12238
148148
obj = index_or_series_obj
149149

150-
if any(isinstance(x, str) for x in obj) and any(isinstance(x, int) for x in obj):
150+
# Handle mixed int string
151+
if isinstance(obj, Index) and obj.inferred_type in ["mixed", "mixed-integer"]:
151152
request.applymarker(
152-
pytest.mark.xfail(reason="Cannot compare mixed types (str and int)")
153+
pytest.mark.xfail(reason="Cannot compare mixed types (str and int)", strict=False)
153154
)
155+
obj = obj.unique()
156+
157+
# Mixed int string specific case
158+
if obj.equals(Index([0, "a", 1, "b", 2, "c"])):
159+
obj = obj.astype(str)
154160

155161
if isinstance(obj, pd.MultiIndex):
156162
# See gh-14833
157163
request.applymarker(
158164
pytest.mark.xfail(
159-
reason="np.searchsorted doesn't work on pd.MultiIndex: GH 14833"
165+
reason="np.searchsorted doesn't work on pd.MultiIndex: GH 14833", strict=False
160166
)
161167
)
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)
168+
return
169+
170+
if obj.dtype.kind == "c" and isinstance(obj, Index):
171+
# Complex numbers are not comparable
172+
request.applymarker(
173+
pytest.mark.xfail(reason="Complex objects are not comparable", strict=False)
174+
)
175+
return
176+
177+
if isinstance(obj, Index) and obj.inferred_type == "tuples":
178+
# Tuples may not be supported by np.searchsorted
179+
pytest.mark.xfail(
180+
reason="Cannot handle tuples in searchsorted", strict=False
181+
)
182+
183+
# Only proceed if obj is not mixed or unsupported
184+
try:
185+
max_obj = max(obj, default=0)
186+
except TypeError:
187+
pytest.mark.xfail(
188+
reason="Cannot compute max for unsupported types", strict=False
189+
)
167190

168-
max_obj = max(obj, default=0)
169191
index = np.searchsorted(obj, max_obj)
170192
assert 0 <= index <= len(obj)
171193

0 commit comments

Comments
 (0)