@@ -152,18 +152,25 @@ class CategoricalDtype(ExtensionDtype): |
|
|
152 |
152 |
_metadata = ['categories', 'ordered'] |
153 |
153 |
_cache = {} |
154 |
154 |
|
155 |
|
-def __new__(cls, categories=None, ordered=False, fastpath=False): |
|
155 |
+def __init__(self, categories=None, ordered=False): |
|
156 |
+self._finalize(categories, ordered, fastpath=False) |
|
157 |
+ |
|
158 |
+@classmethod |
|
159 |
+def _from_fastpath(cls, categories=None, ordered=False): |
|
160 |
+self = cls.__new__(cls) |
|
161 |
+self._finalize(categories, ordered, fastpath=True) |
|
162 |
+return self |
|
163 |
+ |
|
164 |
+def _finalize(self, categories, ordered, fastpath=False): |
156 |
165 |
from pandas.core.indexes.base import Index |
157 |
166 |
|
158 |
167 |
if categories is not None: |
159 |
168 |
categories = Index(categories, tupleize_cols=False) |
160 |
169 |
# validation |
161 |
|
-cls._validate_categories(categories, fastpath=fastpath) |
162 |
|
-cls._validate_ordered(ordered) |
163 |
|
-categorical = object.__new__(cls) |
164 |
|
-categorical._categories = categories |
165 |
|
-categorical._ordered = ordered |
166 |
|
-return categorical |
|
170 |
+self._validate_categories(categories) |
|
171 |
+self._validate_ordered(ordered) |
|
172 |
+self._categories = categories |
|
173 |
+self._ordered = ordered |
167 |
174 |
|
168 |
175 |
def __hash__(self): |
169 |
176 |
# _hash_categories returns a uint64, so use the negative |