Skip to content

Commit 2173c89

Browse files
committed
Consolidating code to fit existing pattern better
1 parent f6d10b8 commit 2173c89

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

pandas/core/arrays/categorical.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -314,16 +314,6 @@ class Categorical(ExtensionArray, PandasObject):
314314
def __init__(self, values, categories=None, ordered=None, dtype=None,
315315
fastpath=False):
316316

317-
# GH23814, for perf, if no optional params used and values already an
318-
# instance of Categorical, simply return the same dtype/codes
319-
if categories is None and ordered is None and dtype is None:
320-
if isinstance(values, (ABCSeries, ABCIndexClass)):
321-
values = values._values
322-
if isinstance(values, type(self)):
323-
self._dtype = values.dtype
324-
self._codes = values.codes.copy()
325-
return
326-
327317
# Ways of specifying the dtype (prioritized ordered)
328318
# 1. dtype is a CategoricalDtype
329319
# a.) with known categories, use dtype.categories
@@ -357,6 +347,16 @@ def __init__(self, values, categories=None, ordered=None, dtype=None,
357347
# the "ordered" and "categories" arguments
358348
dtype = values.dtype._from_categorical_dtype(values.dtype,
359349
categories, ordered)
350+
351+
# GH23814, for perf, if no optional params used and values already
352+
# an instance of Categorical, set values to codes like fastpath
353+
if (isinstance(values, (ABCSeries, ABCIndexClass)) and
354+
isinstance(values._values, type(self))):
355+
values = values._values.codes.copy()
356+
if categories is None:
357+
categories = dtype.categories
358+
fastpath = True
359+
360360
else:
361361
# If dtype=None and values is not categorical, create a new dtype
362362
dtype = CategoricalDtype(categories, ordered)

0 commit comments

Comments
 (0)