17
17
18
18
from pandas .core .dtypes .common import is_list_like
19
19
from 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 )
21
22
from pandas .core .dtypes .missing import isna
22
23
23
24
from pandas .core import ops
@@ -214,8 +215,7 @@ def __getitem__(self, item):
214
215
"""
215
216
raise AbstractMethodError (self )
216
217
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 :
219
219
"""
220
220
Set one or more values inplace.
221
221
@@ -262,8 +262,7 @@ def __setitem__(self, key, value):
262
262
type (self ), '__setitem__' )
263
263
)
264
264
265
- def __len__ (self ):
266
- # type: () -> int
265
+ def __len__ (self ) -> int :
267
266
"""
268
267
Length of this array
269
268
@@ -287,32 +286,28 @@ def __iter__(self):
287
286
# Required attributes
288
287
# ------------------------------------------------------------------------
289
288
@property
290
- def dtype (self ):
291
- # type: () -> ExtensionDtype
289
+ def dtype (self ) -> ExtensionDtype :
292
290
"""
293
291
An instance of 'ExtensionDtype'.
294
292
"""
295
293
raise AbstractMethodError (self )
296
294
297
295
@property
298
- def shape (self ):
299
- # type: () -> Tuple[int, ...]
296
+ def shape (self ) -> Tuple [int , ...]:
300
297
"""
301
298
Return a tuple of the array dimensions.
302
299
"""
303
300
return (len (self ),)
304
301
305
302
@property
306
- def ndim (self ):
307
- # type: () -> int
303
+ def ndim (self ) -> int :
308
304
"""
309
305
Extension Arrays are only allowed to be 1-dimensional.
310
306
"""
311
307
return 1
312
308
313
309
@property
314
- def nbytes (self ):
315
- # type: () -> int
310
+ def nbytes (self ) -> int :
316
311
"""
317
312
The number of bytes needed to store this object in memory.
318
313
"""
@@ -343,8 +338,7 @@ def astype(self, dtype, copy=True):
343
338
"""
344
339
return np .array (self , dtype = dtype , copy = copy )
345
340
346
- def isna (self ):
347
- # type: () -> Union[ExtensionArray, np.ndarray]
341
+ def isna (self ) -> Union [ABCExtensionArray , np .ndarray ]:
348
342
"""
349
343
A 1-D array indicating if each value is missing.
350
344
@@ -366,8 +360,7 @@ def isna(self):
366
360
"""
367
361
raise AbstractMethodError (self )
368
362
369
- def _values_for_argsort (self ):
370
- # type: () -> np.ndarray
363
+ def _values_for_argsort (self ) -> np .ndarray :
371
364
"""
372
365
Return values for sorting.
373
366
@@ -482,8 +475,11 @@ def dropna(self):
482
475
"""
483
476
return self [~ self .isna ()]
484
477
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 :
487
483
"""
488
484
Shift values by desired number.
489
485
@@ -598,8 +594,7 @@ def searchsorted(self, value, side="left", sorter=None):
598
594
arr = self .astype (object )
599
595
return arr .searchsorted (value , side = side , sorter = sorter )
600
596
601
- def _values_for_factorize (self ):
602
- # type: () -> Tuple[np.ndarray, Any]
597
+ def _values_for_factorize (self ) -> Tuple [np .ndarray , Any ]:
603
598
"""
604
599
Return an array and missing value suitable for factorization.
605
600
@@ -623,8 +618,10 @@ def _values_for_factorize(self):
623
618
"""
624
619
return self .astype (object ), np .nan
625
620
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 ]:
628
625
"""
629
626
Encode the extension array as an enumerated type.
630
627
@@ -726,8 +723,12 @@ def repeat(self, repeats, axis=None):
726
723
# Indexing methods
727
724
# ------------------------------------------------------------------------
728
725
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 :
731
732
"""
732
733
Take elements from an array.
733
734
@@ -816,8 +817,7 @@ def take(self, indices, allow_fill=False, fill_value=None):
816
817
# pandas.api.extensions.take
817
818
raise AbstractMethodError (self )
818
819
819
- def copy (self , deep = False ):
820
- # type: (bool) -> ExtensionArray
820
+ def copy (self , deep : bool = False ) -> ABCExtensionArray :
821
821
"""
822
822
Return a copy of the array.
823
823
@@ -853,8 +853,10 @@ def __repr__(self):
853
853
length = len (self ),
854
854
dtype = self .dtype )
855
855
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 ]]:
858
860
"""Formatting function for scalar values.
859
861
860
862
This is used in the default '__repr__'. The returned formatting
@@ -881,8 +883,7 @@ def _formatter(self, boxed=False):
881
883
return str
882
884
return repr
883
885
884
- def _formatting_values (self ):
885
- # type: () -> np.ndarray
886
+ def _formatting_values (self ) -> np .ndarray :
886
887
# At the moment, this has to be an array since we use result.dtype
887
888
"""
888
889
An array of values to be printed in, e.g. the Series repr
@@ -898,8 +899,10 @@ def _formatting_values(self):
898
899
# ------------------------------------------------------------------------
899
900
900
901
@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 :
903
906
"""
904
907
Concatenate multiple array
905
908
@@ -921,8 +924,7 @@ def _concat_same_type(cls, to_concat):
921
924
_can_hold_na = True
922
925
923
926
@property
924
- def _ndarray_values (self ):
925
- # type: () -> np.ndarray
927
+ def _ndarray_values (self ) -> np .ndarray :
926
928
"""
927
929
Internal pandas method for lossy conversion to a NumPy ndarray.
928
930
0 commit comments