@@ -314,16 +314,6 @@ class Categorical(ExtensionArray, PandasObject):
314
314
def __init__ (self , values , categories = None , ordered = None , dtype = None ,
315
315
fastpath = False ):
316
316
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
-
327
317
# Ways of specifying the dtype (prioritized ordered)
328
318
# 1. dtype is a CategoricalDtype
329
319
# a.) with known categories, use dtype.categories
@@ -357,6 +347,16 @@ def __init__(self, values, categories=None, ordered=None, dtype=None,
357
347
# the "ordered" and "categories" arguments
358
348
dtype = values .dtype ._from_categorical_dtype (values .dtype ,
359
349
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
+
360
360
else :
361
361
# If dtype=None and values is not categorical, create a new dtype
362
362
dtype = CategoricalDtype (categories , ordered )
0 commit comments