@@ -97,6 +97,8 @@ class ellipsis(Enum):
97
97
98
98
Ellipsis = ellipsis .Ellipsis
99
99
100
+ SparseIndexKind = Literal ["integer" , "block" ]
101
+
100
102
from pandas ._typing import NumpySorter
101
103
102
104
from pandas import Series
@@ -334,7 +336,7 @@ def __init__(
334
336
sparse_index = None ,
335
337
index = None ,
336
338
fill_value = None ,
337
- kind = "integer" ,
339
+ kind : SparseIndexKind = "integer" ,
338
340
dtype : Dtype | None = None ,
339
341
copy : bool = False ,
340
342
):
@@ -624,7 +626,7 @@ def fill_value(self, value):
624
626
self ._dtype = SparseDtype (self .dtype .subtype , value )
625
627
626
628
@property
627
- def kind (self ) -> str :
629
+ def kind (self ) -> SparseIndexKind :
628
630
"""
629
631
The kind of sparse index for this array. One of {'integer', 'block'}.
630
632
"""
@@ -1676,7 +1678,10 @@ def _formatter(self, boxed=False):
1676
1678
1677
1679
1678
1680
def make_sparse (
1679
- arr : np .ndarray , kind = "block" , fill_value = None , dtype : NpDtype | None = None
1681
+ arr : np .ndarray ,
1682
+ kind : SparseIndexKind = "block" ,
1683
+ fill_value = None ,
1684
+ dtype : NpDtype | None = None ,
1680
1685
):
1681
1686
"""
1682
1687
Convert ndarray to sparse format
@@ -1735,8 +1740,17 @@ def make_sparse(
1735
1740
return sparsified_values , index , fill_value
1736
1741
1737
1742
1738
- def make_sparse_index (length , indices , kind ) -> SparseIndex :
1743
+ @overload
1744
+ def make_sparse_index (length : int , indices , kind : Literal ["block" ]) -> BlockIndex :
1745
+ ...
1746
+
1747
+
1748
+ @overload
1749
+ def make_sparse_index (length : int , indices , kind : Literal ["integer" ]) -> IntIndex :
1750
+ ...
1751
+
1739
1752
1753
+ def make_sparse_index (length : int , indices , kind : SparseIndexKind ) -> SparseIndex :
1740
1754
index : SparseIndex
1741
1755
if kind == "block" or isinstance (kind , BlockIndex ):
1742
1756
locs , lens = splib .get_blocks (indices )
0 commit comments