6
6
from pandas ._config import get_option
7
7
8
8
from pandas ._libs import index as libindex
9
- from pandas ._libs .hashtable import duplicated_int64
10
9
from pandas ._libs .lib import no_default
11
10
from pandas ._typing import ArrayLike , Label
12
11
from pandas .util ._decorators import Appender , cache_readonly , doc
13
12
14
13
from pandas .core .dtypes .common import (
15
14
ensure_platform_int ,
16
15
is_categorical_dtype ,
17
- is_list_like ,
18
16
is_scalar ,
19
17
)
20
18
from pandas .core .dtypes .dtypes import CategoricalDtype
@@ -226,9 +224,14 @@ def _simple_new(cls, values: Categorical, name: Label = None):
226
224
227
225
# --------------------------------------------------------------------
228
226
227
+ # error: Argument 1 of "_shallow_copy" is incompatible with supertype
228
+ # "ExtensionIndex"; supertype defines the argument type as
229
+ # "Optional[ExtensionArray]" [override]
229
230
@doc (Index ._shallow_copy )
230
- def _shallow_copy (
231
- self , values : Optional [Categorical ] = None , name : Label = no_default
231
+ def _shallow_copy ( # type:ignore[override]
232
+ self ,
233
+ values : Optional [Categorical ] = None ,
234
+ name : Label = no_default ,
232
235
):
233
236
name = self .name if name is no_default else name
234
237
@@ -247,6 +250,10 @@ def _is_dtype_compat(self, other) -> Categorical:
247
250
provide a comparison between the dtype of self and other (coercing if
248
251
needed)
249
252
253
+ Parameters
254
+ ----------
255
+ other : Index
256
+
250
257
Returns
251
258
-------
252
259
Categorical
@@ -263,8 +270,6 @@ def _is_dtype_compat(self, other) -> Categorical:
263
270
)
264
271
else :
265
272
values = other
266
- if not is_list_like (values ):
267
- values = [values ]
268
273
269
274
cat = Categorical (other , dtype = self .dtype )
270
275
other = CategoricalIndex (cat )
@@ -358,11 +363,6 @@ def values(self):
358
363
""" return the underlying data, which is a Categorical """
359
364
return self ._data
360
365
361
- @property
362
- def _has_complex_internals (self ) -> bool :
363
- # used to avoid libreduction code paths, which raise or require conversion
364
- return True
365
-
366
366
@doc (Index .__contains__ )
367
367
def __contains__ (self , key : Any ) -> bool :
368
368
# if key is a NaN, check if any NaN is in self.
@@ -399,11 +399,6 @@ def unique(self, level=None):
399
399
# of result, not self.
400
400
return type (self )._simple_new (result , name = self .name )
401
401
402
- @doc (Index .duplicated )
403
- def duplicated (self , keep = "first" ):
404
- codes = self .codes .astype ("i8" )
405
- return duplicated_int64 (codes , keep )
406
-
407
402
def _to_safe_for_reshape (self ):
408
403
""" convert to object if we are a categorical """
409
404
return self .astype ("object" )
@@ -482,7 +477,7 @@ def reindex(self, target, method=None, level=None, limit=None, tolerance=None):
482
477
new_target = np .asarray (new_target )
483
478
if is_categorical_dtype (target ):
484
479
new_target = Categorical (new_target , dtype = target .dtype )
485
- new_target = target . _shallow_copy (new_target , name = self .name )
480
+ new_target = type ( self ). _simple_new (new_target , name = self .name )
486
481
else :
487
482
new_target = Index (new_target , name = self .name )
488
483
@@ -506,7 +501,7 @@ def _reindex_non_unique(self, target):
506
501
# .reindex returns normal Index. Revert to CategoricalIndex if
507
502
# all targets are included in my categories
508
503
new_target = Categorical (new_target , dtype = self .dtype )
509
- new_target = self . _shallow_copy (new_target )
504
+ new_target = type ( self ). _simple_new (new_target , name = self . name )
510
505
511
506
return new_target , indexer , new_indexer
512
507
0 commit comments