From da411b65150beedd5cb8805a0ab66b17cc6d8eab Mon Sep 17 00:00:00 2001 From: shdongre Date: Mon, 21 Apr 2025 18:50:14 +0530 Subject: [PATCH 1/5] add test case for mix string and int --- pandas/conftest.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pandas/conftest.py b/pandas/conftest.py index f9c10a7758bd2..9db58c9a82dd3 100644 --- a/pandas/conftest.py +++ b/pandas/conftest.py @@ -706,6 +706,7 @@ def _create_mi_with_dt64tz_level(): "string-python": Index( pd.array([f"pandas_{i}" for i in range(10)], dtype="string[python]") ), + "mixed-int-string": Index([0, "a", 1, "b", 2, "c"]), } if has_pyarrow: idx = Index(pd.array([f"pandas_{i}" for i in range(10)], dtype="string[pyarrow]")) From 77e46d3ea96e91eb53a5df7bf272f1906dcdec9c Mon Sep 17 00:00:00 2001 From: shdongre Date: Mon, 21 Apr 2025 21:41:19 +0530 Subject: [PATCH 2/5] don't sort array with mixed types str and int --- pandas/conftest.py | 2 +- pandas/tests/base/test_misc.py | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/pandas/conftest.py b/pandas/conftest.py index 9db58c9a82dd3..346be23a180c0 100644 --- a/pandas/conftest.py +++ b/pandas/conftest.py @@ -706,7 +706,7 @@ def _create_mi_with_dt64tz_level(): "string-python": Index( pd.array([f"pandas_{i}" for i in range(10)], dtype="string[python]") ), - "mixed-int-string": Index([0, "a", 1, "b", 2, "c"]), + "mixed-int-string": Index([0, "a", 1, "b", 2, "c"], dtype="mixed-int-string"), } if has_pyarrow: idx = Index(pd.array([f"pandas_{i}" for i in range(10)], dtype="string[pyarrow]")) diff --git a/pandas/tests/base/test_misc.py b/pandas/tests/base/test_misc.py index 7819b7b75f065..6e6e0d7b3b05c 100644 --- a/pandas/tests/base/test_misc.py +++ b/pandas/tests/base/test_misc.py @@ -160,6 +160,10 @@ def test_searchsorted(request, index_or_series_obj): mark = pytest.mark.xfail(reason="complex objects are not comparable") request.applymarker(mark) + elif obj.dtype == "mixed-int-string" and isinstance(obj, Index): + mark = pytest.mark.xfail(reason="np.searchsorted doesn't work on mixed types String and Int: mixed-int-string") + request.applymarker(mark) + max_obj = max(obj, default=0) index = np.searchsorted(obj, max_obj) assert 0 <= index <= len(obj) From 2504717164ca1f154540b0342ab7c1dcab0f842c Mon Sep 17 00:00:00 2001 From: shdongre Date: Mon, 21 Apr 2025 22:18:06 +0530 Subject: [PATCH 3/5] don't test searchSorted on mixed types --- pandas/conftest.py | 2 +- pandas/tests/base/test_misc.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pandas/conftest.py b/pandas/conftest.py index 346be23a180c0..9db58c9a82dd3 100644 --- a/pandas/conftest.py +++ b/pandas/conftest.py @@ -706,7 +706,7 @@ def _create_mi_with_dt64tz_level(): "string-python": Index( pd.array([f"pandas_{i}" for i in range(10)], dtype="string[python]") ), - "mixed-int-string": Index([0, "a", 1, "b", 2, "c"], dtype="mixed-int-string"), + "mixed-int-string": Index([0, "a", 1, "b", 2, "c"]), } if has_pyarrow: idx = Index(pd.array([f"pandas_{i}" for i in range(10)], dtype="string[pyarrow]")) diff --git a/pandas/tests/base/test_misc.py b/pandas/tests/base/test_misc.py index 6e6e0d7b3b05c..437af75c00883 100644 --- a/pandas/tests/base/test_misc.py +++ b/pandas/tests/base/test_misc.py @@ -160,8 +160,8 @@ def test_searchsorted(request, index_or_series_obj): mark = pytest.mark.xfail(reason="complex objects are not comparable") request.applymarker(mark) - elif obj.dtype == "mixed-int-string" and isinstance(obj, Index): - mark = pytest.mark.xfail(reason="np.searchsorted doesn't work on mixed types String and Int: mixed-int-string") + elif set(type(x) for x in obj) > 1 and isinstance(obj, Index): + mark = pytest.mark.xfail(reason="np.searchsorted doesn't work on mixed types") request.applymarker(mark) max_obj = max(obj, default=0) From 7a04711b117ab94042706f881a89dfe14dd49696 Mon Sep 17 00:00:00 2001 From: shdongre Date: Mon, 21 Apr 2025 22:23:21 +0530 Subject: [PATCH 4/5] fix type safety issue --- pandas/tests/base/test_misc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/base/test_misc.py b/pandas/tests/base/test_misc.py index 437af75c00883..0881b346e9836 100644 --- a/pandas/tests/base/test_misc.py +++ b/pandas/tests/base/test_misc.py @@ -160,7 +160,7 @@ def test_searchsorted(request, index_or_series_obj): mark = pytest.mark.xfail(reason="complex objects are not comparable") request.applymarker(mark) - elif set(type(x) for x in obj) > 1 and isinstance(obj, Index): + elif len(set(type(x) for x in obj)) > 1 and isinstance(obj, Index): mark = pytest.mark.xfail(reason="np.searchsorted doesn't work on mixed types") request.applymarker(mark) From c5e76f1825744730cd6211128905701c35b3b1ce Mon Sep 17 00:00:00 2001 From: shdongre Date: Mon, 21 Apr 2025 22:46:52 +0530 Subject: [PATCH 5/5] fix C401 warning --- pandas/tests/base/test_misc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/base/test_misc.py b/pandas/tests/base/test_misc.py index 0881b346e9836..afbce74d4af77 100644 --- a/pandas/tests/base/test_misc.py +++ b/pandas/tests/base/test_misc.py @@ -160,7 +160,7 @@ def test_searchsorted(request, index_or_series_obj): mark = pytest.mark.xfail(reason="complex objects are not comparable") request.applymarker(mark) - elif len(set(type(x) for x in obj)) > 1 and isinstance(obj, Index): + elif len({type(x) for x in obj}) > 1 and isinstance(obj, Index): mark = pytest.mark.xfail(reason="np.searchsorted doesn't work on mixed types") request.applymarker(mark)