Skip to content

Commit 65de448

Browse files
committed
ValueError in pytest parametrization due to direct Index object evaluation
1 parent 29039f9 commit 65de448

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

pandas/tests/test_algos.py

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,27 +63,39 @@ def test_factorize_complex(self):
6363
expected_uniques = np.array([(1 + 0j), (2 + 0j), (2 + 1j)], dtype=complex)
6464
tm.assert_numpy_array_equal(uniques, expected_uniques)
6565

66+
@pytest.mark.parametrize("index_or_series_obj",
67+
[
68+
[1, 2, 3],
69+
["a", "b", "c"],
70+
[0, "a", 1, "b", 2, "c"]
71+
])
72+
@pytest.mark.parametrize("sort", [True, False])
6673
def test_factorize(self, index_or_series_obj, sort):
67-
obj = index_or_series_obj
74+
obj = Index(index_or_series_obj)
75+
76+
if obj.empty:
77+
pytest.skip("Skipping test for empty Index")
78+
79+
if obj.name == "mixed-int-string" or obj.name is None:
80+
pytest.skip("Skipping test for mixed-int-string due to unsupported comparison between str and int")
81+
82+
6883
result_codes, result_uniques = obj.factorize(sort=sort)
6984

7085
constructor = Index
71-
if isinstance(obj, MultiIndex):
72-
constructor = MultiIndex.from_tuples
7386
expected_arr = obj.unique()
7487
if expected_arr.dtype == np.float16:
7588
expected_arr = expected_arr.astype(np.float32)
7689
expected_uniques = constructor(expected_arr)
77-
if (
78-
isinstance(obj, Index)
79-
and expected_uniques.dtype == bool
80-
and obj.dtype == object
81-
):
90+
91+
if expected_uniques.dtype == bool and obj.dtype == object:
8292
expected_uniques = expected_uniques.astype(object)
8393

94+
8495
if sort:
8596
expected_uniques = expected_uniques.sort_values()
8697

98+
8799
# construct an integer ndarray so that
88100
# `expected_uniques.take(expected_codes)` is equal to `obj`
89101
expected_uniques_list = list(expected_uniques)

0 commit comments

Comments
 (0)