Closed
Description
Problem description
I find it inconistent that _get_dtype
accept a CategoricalDtype
, but will thow TypeError on Categorical
s.
Code Sample, a copy-pastable example if possible
>>> cats = pd.Categorical([1,2,3])
>>> pd.core.dtypes.common._get_dtype(cats.dtype)
category
>>> pd.core.dtypes.common._get_dtype(cats)
TypeError: data type not understood
Expected Output
>>> cats = pd.Categorical([1,2,3])
>>> pd.core.dtypes.common._get_dtype(cats.dtype)
category
>>> pd.core.dtypes.common._get_dtype(cats)
category
Proposed solution
A solution could be to check for extension type (maybe just categorical dtype, not sure) + that arr_or_dtype
has a dtype attribute:
def _get_dtypes(arr_or_dtype):
...
elif isinstance(arr_or_dtype, IntervalDtype):
return arr_or_dtype # old code
elif is_extension_type(arr_or_dtype) and hasattr(arr_or_dtype, 'dtype'): # new code
return arr_or_dtype.dtype # new code
elif isinstance(arr_or_dtype, string_types): # old code
...