Skip to content

TST: Add test_factorize_mixed_values #50784

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions pandas/tests/test_algos.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,32 @@ def test_int_factorize_use_na_sentinel_false(
tm.assert_numpy_array_equal(uniques, expected_uniques, strict_nan=True)
tm.assert_numpy_array_equal(codes, expected_codes, strict_nan=True)

@pytest.mark.parametrize(
"data, expected_codes, expected_uniques",
[
(
Index(Categorical(["a", "a", "b"])),
np.array([0, 0, 1], dtype=np.intp),
CategoricalIndex(["a", "b"], categories=["a", "b"], dtype="category"),
),
(
Series(Categorical(["a", "a", "b"])),
np.array([0, 0, 1], dtype=np.intp),
CategoricalIndex(["a", "b"], categories=["a", "b"], dtype="category"),
),
(
Series(DatetimeIndex(["2017", "2017"], tz="US/Eastern")),
np.array([0, 0], dtype=np.intp),
DatetimeIndex(["2017"], tz="US/Eastern"),
),
],
)
def test_factorize_mixed_values(self, data, expected_codes, expected_uniques):
# GH 19721
codes, uniques = algos.factorize(data)
tm.assert_numpy_array_equal(codes, expected_codes)
tm.assert_index_equal(uniques, expected_uniques)


class TestUnique:
def test_ints(self):
Expand Down