44
44
isna ,
45
45
)
46
46
from pandas .core .arrays .categorical import Categorical
47
- from pandas .core .arrays .sparse import BlockIndex , IntIndex
48
47
import pandas .core .common as com
49
48
from pandas .core .computation .pytables import PyTablesExpr , maybe_expression
50
49
from pandas .core .index import ensure_index
@@ -2770,31 +2769,21 @@ def read_array(
2770
2769
else :
2771
2770
return ret
2772
2771
2773
- def read_index (self , key , ** kwargs ):
2772
+ def read_index (self , key : str , ** kwargs ) -> Index :
2774
2773
variety = _ensure_decoded (getattr (self .attrs , f"{ key } _variety" ))
2775
2774
2776
2775
if variety == "multi" :
2777
2776
return self .read_multi_index (key , ** kwargs )
2778
- elif variety == "block" :
2779
- return self .read_block_index (key , ** kwargs )
2780
- elif variety == "sparseint" :
2781
- return self .read_sparse_intindex (key , ** kwargs )
2782
2777
elif variety == "regular" :
2783
2778
_ , index = self .read_index_node (getattr (self .group , key ), ** kwargs )
2784
2779
return index
2785
2780
else : # pragma: no cover
2786
2781
raise TypeError (f"unrecognized index variety: { variety } " )
2787
2782
2788
- def write_index (self , key , index ):
2783
+ def write_index (self , key : str , index : Index ):
2789
2784
if isinstance (index , MultiIndex ):
2790
2785
setattr (self .attrs , f"{ key } _variety" , "multi" )
2791
2786
self .write_multi_index (key , index )
2792
- elif isinstance (index , BlockIndex ):
2793
- setattr (self .attrs , f"{ key } _variety" , "block" )
2794
- self .write_block_index (key , index )
2795
- elif isinstance (index , IntIndex ):
2796
- setattr (self .attrs , f"{ key } _variety" , "sparseint" )
2797
- self .write_sparse_intindex (key , index )
2798
2787
else :
2799
2788
setattr (self .attrs , f"{ key } _variety" , "regular" )
2800
2789
converted = _convert_index ("index" , index , self .encoding , self .errors )
@@ -2808,32 +2797,12 @@ def write_index(self, key, index):
2808
2797
if isinstance (index , (DatetimeIndex , PeriodIndex )):
2809
2798
node ._v_attrs .index_class = self ._class_to_alias (type (index ))
2810
2799
2811
- if hasattr (index , "freq" ):
2800
+ if isinstance (index , ( DatetimeIndex , PeriodIndex , TimedeltaIndex ) ):
2812
2801
node ._v_attrs .freq = index .freq
2813
2802
2814
- if hasattr (index , "tz" ) and index .tz is not None :
2803
+ if isinstance (index , DatetimeIndex ) and index .tz is not None :
2815
2804
node ._v_attrs .tz = _get_tz (index .tz )
2816
2805
2817
- def write_block_index (self , key , index ):
2818
- self .write_array (f"{ key } _blocs" , index .blocs )
2819
- self .write_array (f"{ key } _blengths" , index .blengths )
2820
- setattr (self .attrs , f"{ key } _length" , index .length )
2821
-
2822
- def read_block_index (self , key , ** kwargs ) -> BlockIndex :
2823
- length = getattr (self .attrs , f"{ key } _length" )
2824
- blocs = self .read_array (f"{ key } _blocs" , ** kwargs )
2825
- blengths = self .read_array (f"{ key } _blengths" , ** kwargs )
2826
- return BlockIndex (length , blocs , blengths )
2827
-
2828
- def write_sparse_intindex (self , key , index ):
2829
- self .write_array (f"{ key } _indices" , index .indices )
2830
- setattr (self .attrs , f"{ key } _length" , index .length )
2831
-
2832
- def read_sparse_intindex (self , key , ** kwargs ) -> IntIndex :
2833
- length = getattr (self .attrs , f"{ key } _length" )
2834
- indices = self .read_array (f"{ key } _indices" , ** kwargs )
2835
- return IntIndex (length , indices )
2836
-
2837
2806
def write_multi_index (self , key , index ):
2838
2807
setattr (self .attrs , f"{ key } _nlevels" , index .nlevels )
2839
2808
0 commit comments