@@ -243,7 +243,9 @@ def contains(cat, key, container) -> bool:
243243 return any (loc_ in container for loc_ in loc )
244244
245245
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]
247249 """
248250 Represent a categorical variable in classic R / S-plus fashion.
249251
@@ -561,6 +563,7 @@ def astype(self, dtype: AstypeArg, copy: bool = True) -> ArrayLike:
561563 object is returned.
562564 """
563565 dtype = pandas_dtype (dtype )
566+ result : Categorical | np .ndarray
564567 if self .dtype is dtype :
565568 result = self .copy () if copy else self
566569
@@ -1818,10 +1821,14 @@ def value_counts(self, dropna: bool = True) -> Series:
18181821 ix = np .append (ix , - 1 )
18191822
18201823 ix = coerce_indexer_dtype (ix , self .dtype .categories )
1821- ix = self ._from_backing_data (ix )
1824+ ix_categorical = self ._from_backing_data (ix )
18221825
18231826 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 ,
18251832 )
18261833
18271834 # 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
25262533 result = res_flat .reshape (len (first ), - 1 , order = "F" )
25272534 return result
25282535
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]
25302539 return result
25312540
25322541 # ------------------------------------------------------------------
@@ -2666,11 +2675,11 @@ def _replace(self, *, to_replace, value, inplace: bool = False) -> Self | None:
26662675
26672676 new_categories = ser .take (locs )
26682677 new_categories = new_categories .drop_duplicates (keep = "first" )
2669- new_categories = Index (new_categories )
2678+ index_categories = Index (new_categories )
26702679 new_codes = recode_for_categories (
2671- cat ._codes , all_values , new_categories , copy = False
2680+ cat ._codes , all_values , index_categories , copy = False
26722681 )
2673- new_dtype = CategoricalDtype (new_categories , ordered = self .dtype .ordered )
2682+ new_dtype = CategoricalDtype (index_categories , ordered = self .dtype .ordered )
26742683 NDArrayBacked .__init__ (cat , new_codes , new_dtype )
26752684
26762685 if new_dtype != orig_dtype :
0 commit comments