1717
1818from pandas .core .dtypes .common import is_list_like
1919from pandas .core .dtypes .dtypes import ExtensionDtype
20- from pandas .core .dtypes .generic import ABCIndexClass , ABCSeries
20+ from pandas .core .dtypes .generic import (
21+ ABCExtensionArray , ABCIndexClass , ABCSeries )
2122from pandas .core .dtypes .missing import isna
2223
2324from pandas .core import ops
@@ -214,8 +215,7 @@ def __getitem__(self, item):
214215 """
215216 raise AbstractMethodError (self )
216217
217- def __setitem__ (self , key , value ):
218- # type: (Union[int, np.ndarray], Any) -> None
218+ def __setitem__ (self , key : Union [int , np .ndarray ], value : Any ) -> None :
219219 """
220220 Set one or more values inplace.
221221
@@ -262,8 +262,7 @@ def __setitem__(self, key, value):
262262 type (self ), '__setitem__' )
263263 )
264264
265- def __len__ (self ):
266- # type: () -> int
265+ def __len__ (self ) -> int :
267266 """
268267 Length of this array
269268
@@ -287,32 +286,28 @@ def __iter__(self):
287286 # Required attributes
288287 # ------------------------------------------------------------------------
289288 @property
290- def dtype (self ):
291- # type: () -> ExtensionDtype
289+ def dtype (self ) -> ExtensionDtype :
292290 """
293291 An instance of 'ExtensionDtype'.
294292 """
295293 raise AbstractMethodError (self )
296294
297295 @property
298- def shape (self ):
299- # type: () -> Tuple[int, ...]
296+ def shape (self ) -> Tuple [int , ...]:
300297 """
301298 Return a tuple of the array dimensions.
302299 """
303300 return (len (self ),)
304301
305302 @property
306- def ndim (self ):
307- # type: () -> int
303+ def ndim (self ) -> int :
308304 """
309305 Extension Arrays are only allowed to be 1-dimensional.
310306 """
311307 return 1
312308
313309 @property
314- def nbytes (self ):
315- # type: () -> int
310+ def nbytes (self ) -> int :
316311 """
317312 The number of bytes needed to store this object in memory.
318313 """
@@ -343,8 +338,7 @@ def astype(self, dtype, copy=True):
343338 """
344339 return np .array (self , dtype = dtype , copy = copy )
345340
346- def isna (self ):
347- # type: () -> Union[ExtensionArray, np.ndarray]
341+ def isna (self ) -> Union [ABCExtensionArray , np .ndarray ]:
348342 """
349343 A 1-D array indicating if each value is missing.
350344
@@ -366,8 +360,7 @@ def isna(self):
366360 """
367361 raise AbstractMethodError (self )
368362
369- def _values_for_argsort (self ):
370- # type: () -> np.ndarray
363+ def _values_for_argsort (self ) -> np .ndarray :
371364 """
372365 Return values for sorting.
373366
@@ -482,8 +475,11 @@ def dropna(self):
482475 """
483476 return self [~ self .isna ()]
484477
485- def shift (self , periods = 1 , fill_value = None ):
486- # type: (int, object) -> ExtensionArray
478+ def shift (
479+ self ,
480+ periods : int = 1 ,
481+ fill_value : object = None ,
482+ ) -> ABCExtensionArray :
487483 """
488484 Shift values by desired number.
489485
@@ -598,8 +594,7 @@ def searchsorted(self, value, side="left", sorter=None):
598594 arr = self .astype (object )
599595 return arr .searchsorted (value , side = side , sorter = sorter )
600596
601- def _values_for_factorize (self ):
602- # type: () -> Tuple[np.ndarray, Any]
597+ def _values_for_factorize (self ) -> Tuple [np .ndarray , Any ]:
603598 """
604599 Return an array and missing value suitable for factorization.
605600
@@ -623,8 +618,10 @@ def _values_for_factorize(self):
623618 """
624619 return self .astype (object ), np .nan
625620
626- def factorize (self , na_sentinel = - 1 ):
627- # type: (int) -> Tuple[np.ndarray, ExtensionArray]
621+ def factorize (
622+ self ,
623+ na_sentinel : int = - 1 ,
624+ ) -> Tuple [np .ndarray , ABCExtensionArray ]:
628625 """
629626 Encode the extension array as an enumerated type.
630627
@@ -726,8 +723,12 @@ def repeat(self, repeats, axis=None):
726723 # Indexing methods
727724 # ------------------------------------------------------------------------
728725
729- def take (self , indices , allow_fill = False , fill_value = None ):
730- # type: (Sequence[int], bool, Optional[Any]) -> ExtensionArray
726+ def take (
727+ self ,
728+ indices : Sequence [int ],
729+ allow_fill : bool = False ,
730+ fill_value : Any = None
731+ ) -> ABCExtensionArray :
731732 """
732733 Take elements from an array.
733734
@@ -816,8 +817,7 @@ def take(self, indices, allow_fill=False, fill_value=None):
816817 # pandas.api.extensions.take
817818 raise AbstractMethodError (self )
818819
819- def copy (self , deep = False ):
820- # type: (bool) -> ExtensionArray
820+ def copy (self , deep : bool = False ) -> ABCExtensionArray :
821821 """
822822 Return a copy of the array.
823823
@@ -853,8 +853,10 @@ def __repr__(self):
853853 length = len (self ),
854854 dtype = self .dtype )
855855
856- def _formatter (self , boxed = False ):
857- # type: (bool) -> Callable[[Any], Optional[str]]
856+ def _formatter (
857+ self ,
858+ boxed : bool = False ,
859+ ) -> Callable [[Any ], Optional [str ]]:
858860 """Formatting function for scalar values.
859861
860862 This is used in the default '__repr__'. The returned formatting
@@ -881,8 +883,7 @@ def _formatter(self, boxed=False):
881883 return str
882884 return repr
883885
884- def _formatting_values (self ):
885- # type: () -> np.ndarray
886+ def _formatting_values (self ) -> np .ndarray :
886887 # At the moment, this has to be an array since we use result.dtype
887888 """
888889 An array of values to be printed in, e.g. the Series repr
@@ -898,8 +899,10 @@ def _formatting_values(self):
898899 # ------------------------------------------------------------------------
899900
900901 @classmethod
901- def _concat_same_type (cls , to_concat ):
902- # type: (Sequence[ExtensionArray]) -> ExtensionArray
902+ def _concat_same_type (
903+ cls ,
904+ to_concat : Sequence [ABCExtensionArray ]
905+ ) -> ABCExtensionArray :
903906 """
904907 Concatenate multiple array
905908
@@ -921,8 +924,7 @@ def _concat_same_type(cls, to_concat):
921924 _can_hold_na = True
922925
923926 @property
924- def _ndarray_values (self ):
925- # type: () -> np.ndarray
927+ def _ndarray_values (self ) -> np .ndarray :
926928 """
927929 Internal pandas method for lossy conversion to a NumPy ndarray.
928930
0 commit comments