Skip to content

Commit a1ab12b

Browse files
committed
Fix numpy element from sequence error
1 parent 576a9c6 commit a1ab12b

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

pandas/core/arrays/categorical.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -474,16 +474,16 @@ def to_dummies(self, na_column=None) -> "DataFrame":
474474
--------
475475
:func:`pandas.get_dummies`
476476
"""
477-
from pandas import DataFrame, CategoricalIndex
477+
from pandas import DataFrame, CategoricalIndex, Series
478478

479479
eye = np.eye(len(self.categories) + 1, dtype=bool)
480480
arr = eye[self.codes, :]
481481

482482
if na_column is None:
483483
return DataFrame(arr[:, :-1], columns=CategoricalIndex(self.categories))
484484
else:
485-
cat_lst = list(self.categories) + [na_column]
486-
return DataFrame(arr, columns=CategoricalIndex(cat_lst))
485+
cats = CategoricalIndex(Series(list(self.categories) + [na_column]))
486+
return DataFrame(arr, columns=cats)
487487

488488
@property
489489
def categories(self):

0 commit comments

Comments
 (0)