66 Any ,
77 Literal ,
88 Sequence ,
9- TypeVar ,
109 cast ,
1110 overload ,
1211)
2322 PositionalIndexer2D ,
2423 PositionalIndexerTuple ,
2524 ScalarIndexer ,
25+ Self ,
2626 SequenceIndexer ,
2727 Shape ,
2828 TakeIndexer ,
2929 npt ,
30- type_t ,
3130)
3231from pandas .errors import AbstractMethodError
3332from pandas .util ._decorators import doc
6160from pandas .core .indexers import check_array_indexer
6261from pandas .core .sorting import nargminmax
6362
64- NDArrayBackedExtensionArrayT = TypeVar (
65- "NDArrayBackedExtensionArrayT" , bound = "NDArrayBackedExtensionArray"
66- )
67-
6863if TYPE_CHECKING :
6964 from pandas ._typing import (
7065 NumpySorter ,
@@ -153,13 +148,13 @@ def view(self, dtype: Dtype | None = None) -> ArrayLike:
153148 return arr .view (dtype = dtype ) # type: ignore[arg-type]
154149
155150 def take (
156- self : NDArrayBackedExtensionArrayT ,
151+ self ,
157152 indices : TakeIndexer ,
158153 * ,
159154 allow_fill : bool = False ,
160155 fill_value : Any = None ,
161156 axis : AxisInt = 0 ,
162- ) -> NDArrayBackedExtensionArrayT :
157+ ) -> Self :
163158 if allow_fill :
164159 fill_value = self ._validate_scalar (fill_value )
165160
@@ -218,17 +213,17 @@ def argmax(self, axis: AxisInt = 0, skipna: bool = True): # type: ignore[overri
218213 raise NotImplementedError
219214 return nargminmax (self , "argmax" , axis = axis )
220215
221- def unique (self : NDArrayBackedExtensionArrayT ) -> NDArrayBackedExtensionArrayT :
216+ def unique (self ) -> Self :
222217 new_data = unique (self ._ndarray )
223218 return self ._from_backing_data (new_data )
224219
225220 @classmethod
226221 @doc (ExtensionArray ._concat_same_type )
227222 def _concat_same_type (
228- cls : type [ NDArrayBackedExtensionArrayT ] ,
229- to_concat : Sequence [NDArrayBackedExtensionArrayT ],
223+ cls ,
224+ to_concat : Sequence [Self ],
230225 axis : AxisInt = 0 ,
231- ) -> NDArrayBackedExtensionArrayT :
226+ ) -> Self :
232227 dtypes = {str (x .dtype ) for x in to_concat }
233228 if len (dtypes ) != 1 :
234229 raise ValueError ("to_concat must have the same dtype (tz)" , dtypes )
@@ -268,15 +263,15 @@ def __getitem__(self, key: ScalarIndexer) -> Any:
268263
269264 @overload
270265 def __getitem__ (
271- self : NDArrayBackedExtensionArrayT ,
266+ self ,
272267 key : SequenceIndexer | PositionalIndexerTuple ,
273- ) -> NDArrayBackedExtensionArrayT :
268+ ) -> Self :
274269 ...
275270
276271 def __getitem__ (
277- self : NDArrayBackedExtensionArrayT ,
272+ self ,
278273 key : PositionalIndexer2D ,
279- ) -> NDArrayBackedExtensionArrayT | Any :
274+ ) -> Self | Any :
280275 if lib .is_integer (key ):
281276 # fast-path
282277 result = self ._ndarray [key ]
@@ -303,9 +298,7 @@ def _fill_mask_inplace(
303298 func (self ._ndarray .T , limit = limit , mask = mask .T )
304299
305300 @doc (ExtensionArray .fillna )
306- def fillna (
307- self : NDArrayBackedExtensionArrayT , value = None , method = None , limit = None
308- ) -> NDArrayBackedExtensionArrayT :
301+ def fillna (self , value = None , method = None , limit = None ) -> Self :
309302 value , method = validate_fillna_kwargs (
310303 value , method , validate_scalar_dict_value = False
311304 )
@@ -369,9 +362,7 @@ def _putmask(self, mask: npt.NDArray[np.bool_], value) -> None:
369362
370363 np .putmask (self ._ndarray , mask , value )
371364
372- def _where (
373- self : NDArrayBackedExtensionArrayT , mask : npt .NDArray [np .bool_ ], value
374- ) -> NDArrayBackedExtensionArrayT :
365+ def _where (self : Self , mask : npt .NDArray [np .bool_ ], value ) -> Self :
375366 """
376367 Analogue to np.where(mask, self, value)
377368
@@ -393,9 +384,7 @@ def _where(
393384 # ------------------------------------------------------------------------
394385 # Index compat methods
395386
396- def insert (
397- self : NDArrayBackedExtensionArrayT , loc : int , item
398- ) -> NDArrayBackedExtensionArrayT :
387+ def insert (self , loc : int , item ) -> Self :
399388 """
400389 Make new ExtensionArray inserting new item at location. Follows
401390 Python list.append semantics for negative values.
@@ -461,10 +450,10 @@ def value_counts(self, dropna: bool = True) -> Series:
461450 return Series (result ._values , index = index , name = result .name )
462451
463452 def _quantile (
464- self : NDArrayBackedExtensionArrayT ,
453+ self ,
465454 qs : npt .NDArray [np .float64 ],
466455 interpolation : str ,
467- ) -> NDArrayBackedExtensionArrayT :
456+ ) -> Self :
468457 # TODO: disable for Categorical if not ordered?
469458
470459 mask = np .asarray (self .isna ())
@@ -488,9 +477,7 @@ def _cast_quantile_result(self, res_values: np.ndarray) -> np.ndarray:
488477 # numpy-like methods
489478
490479 @classmethod
491- def _empty (
492- cls : type_t [NDArrayBackedExtensionArrayT ], shape : Shape , dtype : ExtensionDtype
493- ) -> NDArrayBackedExtensionArrayT :
480+ def _empty (cls , shape : Shape , dtype : ExtensionDtype ) -> Self :
494481 """
495482 Analogous to np.empty(shape, dtype=dtype)
496483
0 commit comments