@@ -341,9 +341,6 @@ def __init__(self, values, categories=None, ordered=None, dtype=None,
341341 elif categories is not None or ordered is not None :
342342 raise ValueError ("Cannot specify both `dtype` and `categories`"
343343 " or `ordered`." )
344-
345- categories = dtype .categories
346-
347344 elif is_categorical (values ):
348345 # If no "dtype" was passed, use the one from "values", but honor
349346 # the "ordered" and "categories" arguments
@@ -355,19 +352,17 @@ def __init__(self, values, categories=None, ordered=None, dtype=None,
355352 if (isinstance (values , (ABCSeries , ABCIndexClass )) and
356353 isinstance (values ._values , type (self ))):
357354 values = values ._values .codes .copy ()
358- if categories is None :
359- categories = dtype .categories
360355 fastpath = True
361-
362356 else :
363357 # If dtype=None and values is not categorical, create a new dtype
364358 dtype = CategoricalDtype (categories , ordered )
365359
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.
367362 # if dtype.categories is None, we are inferring
368363
369364 if fastpath :
370- self ._codes = coerce_indexer_dtype (values , categories )
365+ self ._codes = coerce_indexer_dtype (values , dtype . categories )
371366 self ._dtype = self ._dtype .update_dtype (dtype )
372367 return
373368
@@ -379,7 +374,6 @@ def __init__(self, values, categories=None, ordered=None, dtype=None,
379374 if is_categorical_dtype (values ):
380375 if dtype .categories is None :
381376 dtype = CategoricalDtype (values .categories , dtype .ordered )
382-
383377 elif not isinstance (values , (ABCIndexClass , ABCSeries )):
384378 # sanitize_array coerces np.nan to a string under certain versions
385379 # of numpy
0 commit comments