diff --git a/pandas/conftest.py b/pandas/conftest.py index d7e8fbeb9336b..14a107d563d62 100644 --- a/pandas/conftest.py +++ b/pandas/conftest.py @@ -619,6 +619,7 @@ def _create_mi_with_dt64tz_level(): "tuples": MultiIndex.from_tuples(zip(["foo", "bar", "baz"], [1, 2, 3])), "mi-with-dt64tz-level": _create_mi_with_dt64tz_level(), "multi": _create_multiindex(), + "mixed-int-string": Index([0, "a", 1, "b", 2, "c"]), "repeats": Index([0, 0, 1, 1, 2, 2]), "nullable_int": Index(np.arange(100), dtype="Int64"), "nullable_uint": Index(np.arange(100), dtype="UInt16"), diff --git a/pandas/tests/base/test_value_counts.py b/pandas/tests/base/test_value_counts.py index 89f3c005c52f0..fc3743ffe150b 100644 --- a/pandas/tests/base/test_value_counts.py +++ b/pandas/tests/base/test_value_counts.py @@ -33,6 +33,7 @@ def test_value_counts(index_or_series_obj): with pytest.raises(NotImplementedError, match="float16 indexes are not "): expected.index.astype(obj.dtype) return + if isinstance(expected.index, MultiIndex): expected.index.names = obj.names else: @@ -47,21 +48,27 @@ def test_value_counts(index_or_series_obj): # TODO(GH#32514): Order of entries with the same count is inconsistent # on CI (gh-32449) - if obj.duplicated().any(): - result = result.sort_index() - expected = expected.sort_index() - tm.assert_series_equal(result, expected) + try: + if obj.duplicated().any(): + result = result.sort_index() + expected = expected.sort_index() + tm.assert_series_equal(result, expected) + except TypeError: + pytest.xfail("dtypes not suitable for sorting.") @pytest.mark.parametrize("null_obj", [np.nan, None]) def test_value_counts_null(null_obj, index_or_series_obj): orig = index_or_series_obj obj = orig.copy() + present_types = set([type(i) for i in obj]) if not allow_na_ops(obj): pytest.skip("type doesn't allow for NA operations") elif len(obj) < 1: pytest.skip("Test doesn't make sense on empty data") + elif len(present_types) > 1: + pytest.skip("Test doesn't make sense on data with different index types.") elif isinstance(orig, MultiIndex): pytest.skip(f"MultiIndex can't hold '{null_obj}'") diff --git a/pandas/tests/test_algos.py b/pandas/tests/test_algos.py index 34a0bee877664..1fc326610d8d6 100644 --- a/pandas/tests/test_algos.py +++ b/pandas/tests/test_algos.py @@ -71,7 +71,10 @@ def test_factorize(self, index_or_series_obj, sort): expected_uniques = expected_uniques.astype(object) if sort: - expected_uniques = expected_uniques.sort_values() + try: + expected_uniques = expected_uniques.sort_values() + except TypeError: + pytest.xfail("dtypes not suitable for sorting.") # construct an integer ndarray so that # `expected_uniques.take(expected_codes)` is equal to `obj`