@@ -243,7 +243,9 @@ def contains(cat, key, container) -> bool:
243
243
return any (loc_ in container for loc_ in loc )
244
244
245
245
246
- class Categorical (NDArrayBackedExtensionArray , PandasObject , ObjectStringArrayMixin ):
246
+ # error: Definition of "delete/ravel/T/repeat/copy" in base class "NDArrayBacked"
247
+ # is incompatible with definition in base class "ExtensionArray"
248
+ class Categorical (NDArrayBackedExtensionArray , PandasObject , ObjectStringArrayMixin ): # type: ignore[misc]
247
249
"""
248
250
Represent a categorical variable in classic R / S-plus fashion.
249
251
@@ -561,6 +563,7 @@ def astype(self, dtype: AstypeArg, copy: bool = True) -> ArrayLike:
561
563
object is returned.
562
564
"""
563
565
dtype = pandas_dtype (dtype )
566
+ result : Categorical | np .ndarray
564
567
if self .dtype is dtype :
565
568
result = self .copy () if copy else self
566
569
@@ -1818,10 +1821,14 @@ def value_counts(self, dropna: bool = True) -> Series:
1818
1821
ix = np .append (ix , - 1 )
1819
1822
1820
1823
ix = coerce_indexer_dtype (ix , self .dtype .categories )
1821
- ix = self ._from_backing_data (ix )
1824
+ ix_categorical = self ._from_backing_data (ix )
1822
1825
1823
1826
return Series (
1824
- count , index = CategoricalIndex (ix ), dtype = "int64" , name = "count" , copy = False
1827
+ count ,
1828
+ index = CategoricalIndex (ix_categorical ),
1829
+ dtype = "int64" ,
1830
+ name = "count" ,
1831
+ copy = False ,
1825
1832
)
1826
1833
1827
1834
# error: Argument 2 of "_empty" is incompatible with supertype
@@ -2526,7 +2533,9 @@ def _concat_same_type(cls, to_concat: Sequence[Self], axis: AxisInt = 0) -> Self
2526
2533
result = res_flat .reshape (len (first ), - 1 , order = "F" )
2527
2534
return result
2528
2535
2529
- result = union_categoricals (to_concat )
2536
+ # error: Incompatible types in assignment (expression has type "Categorical",
2537
+ # variable has type "Self")
2538
+ result = union_categoricals (to_concat ) # type: ignore[assignment]
2530
2539
return result
2531
2540
2532
2541
# ------------------------------------------------------------------
@@ -2666,11 +2675,11 @@ def _replace(self, *, to_replace, value, inplace: bool = False) -> Self | None:
2666
2675
2667
2676
new_categories = ser .take (locs )
2668
2677
new_categories = new_categories .drop_duplicates (keep = "first" )
2669
- new_categories = Index (new_categories )
2678
+ index_categories = Index (new_categories )
2670
2679
new_codes = recode_for_categories (
2671
- cat ._codes , all_values , new_categories , copy = False
2680
+ cat ._codes , all_values , index_categories , copy = False
2672
2681
)
2673
- new_dtype = CategoricalDtype (new_categories , ordered = self .dtype .ordered )
2682
+ new_dtype = CategoricalDtype (index_categories , ordered = self .dtype .ordered )
2674
2683
NDArrayBacked .__init__ (cat , new_codes , new_dtype )
2675
2684
2676
2685
if new_dtype != orig_dtype :
0 commit comments