@@ -106,15 +106,23 @@ class to receive bound method
106
106
else :
107
107
setattr (cls , name , func )
108
108
109
+ class CategoricalDtypeType (type ):
110
+ """
111
+ the type of CategoricalDtype, this metaclass determines subclass ability
112
+ """
113
+ def __init__ (cls , name , bases , attrs ):
114
+ pass
115
+
109
116
class CategoricalDtype (object ):
117
+ __meta__ = CategoricalDtypeType
110
118
"""
111
119
A np.dtype duck-typed class, suitable for holding a custom categorical dtype.
112
120
113
121
THIS IS NOT A REAL NUMPY DTYPE, but essentially a sub-class of np.object
114
122
"""
115
123
name = 'category'
116
124
names = None
117
- type = np . object_
125
+ type = CategoricalDtypeType
118
126
subdtype = None
119
127
kind = 'O'
120
128
str = '|O08'
@@ -1702,6 +1710,8 @@ def _get_dtype_from_object(dtype):
1702
1710
elif isinstance (dtype , compat .string_types ):
1703
1711
if dtype == 'datetime' or dtype == 'timedelta' :
1704
1712
dtype += '64'
1713
+ elif dtype == 'category' :
1714
+ return CategoricalDtypeType
1705
1715
try :
1706
1716
return _get_dtype_from_object (getattr (np , dtype ))
1707
1717
except AttributeError :
@@ -1712,10 +1722,6 @@ def _get_dtype_from_object(dtype):
1712
1722
return _get_dtype_from_object (np .dtype (dtype ))
1713
1723
1714
1724
1715
- _string_dtypes = frozenset (map (_get_dtype_from_object , (compat .binary_type ,
1716
- compat .text_type )))
1717
-
1718
-
1719
1725
def _get_info_slice (obj , indexer ):
1720
1726
"""Slice the info axis of `obj` with `indexer`."""
1721
1727
if not hasattr (obj , '_info_axis_number' ):
@@ -2383,6 +2389,7 @@ def is_bool_dtype(arr_or_dtype):
2383
2389
def is_categorical_dtype (arr_or_dtype ):
2384
2390
if hasattr (arr_or_dtype ,'dtype' ):
2385
2391
arr_or_dtype = arr_or_dtype .dtype
2392
+
2386
2393
if isinstance (arr_or_dtype , CategoricalDtype ):
2387
2394
return True
2388
2395
try :
@@ -2427,6 +2434,10 @@ def _is_sequence(x):
2427
2434
return False
2428
2435
2429
2436
2437
+ _string_dtypes = frozenset (map (_get_dtype_from_object , (compat .binary_type ,
2438
+ compat .text_type )))
2439
+
2440
+
2430
2441
_ensure_float64 = algos .ensure_float64
2431
2442
_ensure_float32 = algos .ensure_float32
2432
2443
_ensure_int64 = algos .ensure_int64
0 commit comments