Skip to content

Commit 320325a

Browse files
committed
Test categorical <-> dummies roundtrip
1 parent 35ec501 commit 320325a

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

pandas/tests/arrays/categorical/test_api.py

+16
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,22 @@ def test_to_dummies_na_dtype(self):
422422
dummies = cats.to_dummies(na_column="other")
423423
assert dummies.columns.categories.dtype == object
424424

425+
@pytest.mark.parametrize(
426+
"vals",
427+
[
428+
["a", "b", "b", "a"],
429+
["a", "b", "b", "a", np.nan],
430+
[1, 1.5, "a", (1, "b")],
431+
[1, 1.5, "a", (1, "b"), np.nan],
432+
],
433+
)
434+
def test_dummies_roundtrip(self, vals):
435+
# GH 8745
436+
cats = Categorical(Series(vals))
437+
dummies = cats.to_dummies()
438+
cats2 = Categorical.from_dummies(dummies)
439+
tm.assert_equal(cats, cats2)
440+
425441

426442
class TestCategoricalAPIWithFactor(TestCategorical):
427443
def test_describe(self):

0 commit comments

Comments
 (0)