Skip to content

Commit b20fbe5

Browse files
committed
PERF: avoid casting categorical to array
1 parent 717b888 commit b20fbe5

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

pandas/core/categorical.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,8 @@ def __init__(self, values, categories=None, ordered=None, dtype=None,
293293

294294
# sanitize input
295295
if is_categorical_dtype(values):
296-
values = values.get_values()
296+
if dtype.categories is None:
297+
dtype = CategoricalDtype(values.categories, dtype.ordered)
297298

298299
elif isinstance(values, (ABCIndexClass, ABCSeries)):
299300
# we'll do inference later
@@ -337,9 +338,8 @@ def __init__(self, values, categories=None, ordered=None, dtype=None,
337338
raise NotImplementedError("> 1 ndim Categorical are not "
338339
"supported at this time")
339340

340-
if dtype.categories is None:
341-
# we're inferring from values
342-
dtype = CategoricalDtype(categories, dtype.ordered)
341+
# we're inferring from values
342+
dtype = CategoricalDtype(categories, dtype.ordered)
343343

344344
else:
345345
# there were two ways if categories are present

0 commit comments

Comments
 (0)