@@ -98,6 +98,8 @@ class ellipsis(Enum):
98
98
99
99
from pandas ._typing import NumpySorter
100
100
101
+ from pandas import Series
102
+
101
103
else :
102
104
ellipsis = type (Ellipsis )
103
105
@@ -328,7 +330,7 @@ def __init__(
328
330
fill_value = None ,
329
331
kind = "integer" ,
330
332
dtype : Dtype | None = None ,
331
- copy = False ,
333
+ copy : bool = False ,
332
334
):
333
335
334
336
if fill_value is None and isinstance (dtype , SparseDtype ):
@@ -558,7 +560,7 @@ def __setitem__(self, key, value):
558
560
raise TypeError (msg )
559
561
560
562
@classmethod
561
- def _from_sequence (cls , scalars , * , dtype : Dtype | None = None , copy = False ):
563
+ def _from_sequence (cls , scalars , * , dtype : Dtype | None = None , copy : bool = False ):
562
564
return cls (scalars , dtype = dtype )
563
565
564
566
@classmethod
@@ -625,10 +627,10 @@ def __len__(self) -> int:
625
627
return self .sp_index .length
626
628
627
629
@property
628
- def _null_fill_value (self ):
630
+ def _null_fill_value (self ) -> bool :
629
631
return self ._dtype ._is_na_fill_value
630
632
631
- def _fill_value_matches (self , fill_value ):
633
+ def _fill_value_matches (self , fill_value ) -> bool :
632
634
if self ._null_fill_value :
633
635
return isna (fill_value )
634
636
else :
@@ -725,7 +727,7 @@ def fillna(self, value=None, method=None, limit=None):
725
727
726
728
return self ._simple_new (new_values , self ._sparse_index , new_dtype )
727
729
728
- def shift (self , periods = 1 , fill_value = None ):
730
+ def shift (self , periods : int = 1 , fill_value = None ):
729
731
730
732
if not len (self ) or periods == 0 :
731
733
return self .copy ()
@@ -794,7 +796,7 @@ def factorize(self, na_sentinel=-1):
794
796
uniques = SparseArray (uniques , dtype = self .dtype ) # type: ignore[assignment]
795
797
return codes , uniques
796
798
797
- def value_counts (self , dropna : bool = True ):
799
+ def value_counts (self , dropna : bool = True ) -> Series :
798
800
"""
799
801
Returns a Series containing counts of unique values.
800
802
@@ -909,24 +911,28 @@ def _get_val_at(self, loc):
909
911
val = maybe_box_datetimelike (val , self .sp_values .dtype )
910
912
return val
911
913
912
- def take (self , indices , * , allow_fill = False , fill_value = None ) -> SparseArray :
914
+ def take (
915
+ self , indices , * , allow_fill : bool = False , fill_value = None
916
+ ) -> SparseArray :
913
917
if is_scalar (indices ):
914
918
raise ValueError (f"'indices' must be an array, not a scalar '{ indices } '." )
915
919
indices = np .asarray (indices , dtype = np .int32 )
916
920
921
+ dtype = None
917
922
if indices .size == 0 :
918
923
result = np .array ([], dtype = "object" )
919
- kwargs = { "dtype" : self .dtype }
924
+ dtype = self .dtype
920
925
elif allow_fill :
921
926
result = self ._take_with_fill (indices , fill_value = fill_value )
922
- kwargs = {}
923
927
else :
924
928
# error: Incompatible types in assignment (expression has type
925
929
# "Union[ndarray, SparseArray]", variable has type "ndarray")
926
930
result = self ._take_without_fill (indices ) # type: ignore[assignment]
927
- kwargs = { "dtype" : self .dtype }
931
+ dtype = self .dtype
928
932
929
- return type (self )(result , fill_value = self .fill_value , kind = self .kind , ** kwargs )
933
+ return type (self )(
934
+ result , fill_value = self .fill_value , kind = self .kind , dtype = dtype
935
+ )
930
936
931
937
def _take_with_fill (self , indices , fill_value = None ) -> np .ndarray :
932
938
if fill_value is None :
@@ -1104,7 +1110,7 @@ def _concat_same_type(
1104
1110
1105
1111
return cls (data , sparse_index = sp_index , fill_value = fill_value )
1106
1112
1107
- def astype (self , dtype : AstypeArg | None = None , copy = True ):
1113
+ def astype (self , dtype : AstypeArg | None = None , copy : bool = True ):
1108
1114
"""
1109
1115
Change the dtype of a SparseArray.
1110
1116
0 commit comments