4444 isna ,
4545)
4646from pandas .core .arrays .categorical import Categorical
47- from pandas .core .arrays .sparse import BlockIndex , IntIndex
4847import pandas .core .common as com
4948from pandas .core .computation .pytables import PyTablesExpr , maybe_expression
5049from pandas .core .index import ensure_index
@@ -2770,31 +2769,21 @@ def read_array(
27702769 else :
27712770 return ret
27722771
2773- def read_index (self , key , ** kwargs ):
2772+ def read_index (self , key : str , ** kwargs ) -> Index :
27742773 variety = _ensure_decoded (getattr (self .attrs , f"{ key } _variety" ))
27752774
27762775 if variety == "multi" :
27772776 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 )
27822777 elif variety == "regular" :
27832778 _ , index = self .read_index_node (getattr (self .group , key ), ** kwargs )
27842779 return index
27852780 else : # pragma: no cover
27862781 raise TypeError (f"unrecognized index variety: { variety } " )
27872782
2788- def write_index (self , key , index ):
2783+ def write_index (self , key : str , index : Index ):
27892784 if isinstance (index , MultiIndex ):
27902785 setattr (self .attrs , f"{ key } _variety" , "multi" )
27912786 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 )
27982787 else :
27992788 setattr (self .attrs , f"{ key } _variety" , "regular" )
28002789 converted = _convert_index ("index" , index , self .encoding , self .errors )
@@ -2808,32 +2797,12 @@ def write_index(self, key, index):
28082797 if isinstance (index , (DatetimeIndex , PeriodIndex )):
28092798 node ._v_attrs .index_class = self ._class_to_alias (type (index ))
28102799
2811- if hasattr (index , "freq" ):
2800+ if isinstance (index , ( DatetimeIndex , PeriodIndex , TimedeltaIndex ) ):
28122801 node ._v_attrs .freq = index .freq
28132802
2814- if hasattr (index , "tz" ) and index .tz is not None :
2803+ if isinstance (index , DatetimeIndex ) and index .tz is not None :
28152804 node ._v_attrs .tz = _get_tz (index .tz )
28162805
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-
28372806 def write_multi_index (self , key , index ):
28382807 setattr (self .attrs , f"{ key } _nlevels" , index .nlevels )
28392808
0 commit comments