Skip to content

Commit 8d296f2

Browse files
authored
TST: Add test_factorize_mixed_values (#50784)
add test_factorize_mixed_values
1 parent affcdf9 commit 8d296f2

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

pandas/tests/test_algos.py

+26
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,32 @@ def test_int_factorize_use_na_sentinel_false(
505505
tm.assert_numpy_array_equal(uniques, expected_uniques, strict_nan=True)
506506
tm.assert_numpy_array_equal(codes, expected_codes, strict_nan=True)
507507

508+
@pytest.mark.parametrize(
509+
"data, expected_codes, expected_uniques",
510+
[
511+
(
512+
Index(Categorical(["a", "a", "b"])),
513+
np.array([0, 0, 1], dtype=np.intp),
514+
CategoricalIndex(["a", "b"], categories=["a", "b"], dtype="category"),
515+
),
516+
(
517+
Series(Categorical(["a", "a", "b"])),
518+
np.array([0, 0, 1], dtype=np.intp),
519+
CategoricalIndex(["a", "b"], categories=["a", "b"], dtype="category"),
520+
),
521+
(
522+
Series(DatetimeIndex(["2017", "2017"], tz="US/Eastern")),
523+
np.array([0, 0], dtype=np.intp),
524+
DatetimeIndex(["2017"], tz="US/Eastern"),
525+
),
526+
],
527+
)
528+
def test_factorize_mixed_values(self, data, expected_codes, expected_uniques):
529+
# GH 19721
530+
codes, uniques = algos.factorize(data)
531+
tm.assert_numpy_array_equal(codes, expected_codes)
532+
tm.assert_index_equal(uniques, expected_uniques)
533+
508534

509535
class TestUnique:
510536
def test_ints(self):

0 commit comments

Comments
 (0)