@@ -341,9 +341,6 @@ def __init__(self, values, categories=None, ordered=None, dtype=None,
341
341
elif categories is not None or ordered is not None :
342
342
raise ValueError ("Cannot specify both `dtype` and `categories`"
343
343
" or `ordered`." )
344
-
345
- categories = dtype .categories
346
-
347
344
elif is_categorical (values ):
348
345
# If no "dtype" was passed, use the one from "values", but honor
349
346
# the "ordered" and "categories" arguments
@@ -355,19 +352,17 @@ def __init__(self, values, categories=None, ordered=None, dtype=None,
355
352
if (isinstance (values , (ABCSeries , ABCIndexClass )) and
356
353
isinstance (values ._values , type (self ))):
357
354
values = values ._values .codes .copy ()
358
- if categories is None :
359
- categories = dtype .categories
360
355
fastpath = True
361
-
362
356
else :
363
357
# If dtype=None and values is not categorical, create a new dtype
364
358
dtype = CategoricalDtype (categories , ordered )
365
359
366
- # At this point, dtype is always a CategoricalDtype
360
+ # At this point, dtype is always a CategoricalDtype and you should not
361
+ # use categories and ordered seperately.
367
362
# if dtype.categories is None, we are inferring
368
363
369
364
if fastpath :
370
- self ._codes = coerce_indexer_dtype (values , categories )
365
+ self ._codes = coerce_indexer_dtype (values , dtype . categories )
371
366
self ._dtype = self ._dtype .update_dtype (dtype )
372
367
return
373
368
@@ -379,7 +374,6 @@ def __init__(self, values, categories=None, ordered=None, dtype=None,
379
374
if is_categorical_dtype (values ):
380
375
if dtype .categories is None :
381
376
dtype = CategoricalDtype (values .categories , dtype .ordered )
382
-
383
377
elif not isinstance (values , (ABCIndexClass , ABCSeries )):
384
378
# sanitize_array coerces np.nan to a string under certain versions
385
379
# of numpy
0 commit comments