4
4
from collections import abc
5
5
import numbers
6
6
import operator
7
- from typing import Any , Callable
7
+ from typing import Any , Callable , Union
8
8
import warnings
9
9
10
10
import numpy as np
@@ -479,7 +479,7 @@ def sp_index(self):
479
479
return self ._sparse_index
480
480
481
481
@property
482
- def sp_values (self ):
482
+ def sp_values (self ) -> np . ndarray :
483
483
"""
484
484
An ndarray containing the non- ``fill_value`` values.
485
485
@@ -798,13 +798,13 @@ def _get_val_at(self, loc):
798
798
val = com .maybe_box_datetimelike (val , self .sp_values .dtype )
799
799
return val
800
800
801
- def take (self , indices , allow_fill = False , fill_value = None ):
801
+ def take (self , indices , allow_fill = False , fill_value = None ) -> "SparseArray" :
802
802
if is_scalar (indices ):
803
803
raise ValueError (f"'indices' must be an array, not a scalar '{ indices } '." )
804
804
indices = np .asarray (indices , dtype = np .int32 )
805
805
806
806
if indices .size == 0 :
807
- result = []
807
+ result = np . array ([], dtype = "object" )
808
808
kwargs = {"dtype" : self .dtype }
809
809
elif allow_fill :
810
810
result = self ._take_with_fill (indices , fill_value = fill_value )
@@ -815,7 +815,7 @@ def take(self, indices, allow_fill=False, fill_value=None):
815
815
816
816
return type (self )(result , fill_value = self .fill_value , kind = self .kind , ** kwargs )
817
817
818
- def _take_with_fill (self , indices , fill_value = None ):
818
+ def _take_with_fill (self , indices , fill_value = None ) -> np . ndarray :
819
819
if fill_value is None :
820
820
fill_value = self .dtype .na_value
821
821
@@ -878,7 +878,7 @@ def _take_with_fill(self, indices, fill_value=None):
878
878
879
879
return taken
880
880
881
- def _take_without_fill (self , indices ):
881
+ def _take_without_fill (self , indices ) -> Union [ np . ndarray , "SparseArray" ] :
882
882
to_shift = indices < 0
883
883
indices = indices .copy ()
884
884
0 commit comments