Skip to content

Commit 52b6900

Browse files
committed
Test to_dummies column type cast
1 parent a1ab12b commit 52b6900

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

pandas/tests/arrays/categorical/test_api.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -410,9 +410,18 @@ def test_remove_unused_categories(self):
410410
)
411411
def test_to_dummies(self, vals):
412412
# GH 8745
413-
cats = Categorical(vals)
413+
cats = Categorical(Series(vals))
414414
tm.assert_equal(cats.to_dummies(), get_dummies(cats).astype(bool))
415415

416+
def test_to_dummies_na_dtype(self):
417+
# when dtype of NA column name != dtype of categories,
418+
# check the cast to object
419+
# GH 8745
420+
cats = Categorical([1, 2, 2, 1, np.nan])
421+
assert cats.dtype != object
422+
dummies = cats.to_dummies(na_column="other")
423+
assert dummies.columns.dtype == object
424+
416425

417426
class TestCategoricalAPIWithFactor(TestCategorical):
418427
def test_describe(self):

0 commit comments

Comments
 (0)