@@ -183,7 +183,7 @@ class DuplicateWarning(Warning):
183
183
"series" : "SeriesFixed" ,
184
184
"sparse_series" : "SeriesFixed" ,
185
185
"frame" : "FrameFixed" ,
186
- "sparse_frame" : "FrameFixed " ,
186
+ "sparse_frame" : "SparseFrameFixed " ,
187
187
}
188
188
189
189
# table class map
@@ -2722,6 +2722,18 @@ def write(self, obj, **kwargs):
2722
2722
2723
2723
def read_array (self , key , start = None , stop = None ):
2724
2724
""" read an array for the specified node (off of group """
2725
+ if (
2726
+ self .pandas_type == "sparse_series" or "sp_index_length" in self .attrs
2727
+ ) and key not in self .group :
2728
+ # Compatibility for files written with pandas 0.25.1 and earlier.
2729
+ if "sp_values" in self .group :
2730
+ key = "sp_values"
2731
+ dtype = "Sparse"
2732
+ sp_index = self .read_index ("sp_index" .format (key ))
2733
+ else :
2734
+ dtype = None
2735
+ sp_index = None
2736
+
2725
2737
import tables
2726
2738
2727
2739
node = getattr (self .group , key )
@@ -2732,7 +2744,7 @@ def read_array(self, key, start=None, stop=None):
2732
2744
if isinstance (node , tables .VLArray ):
2733
2745
ret = node [0 ][start :stop ]
2734
2746
else :
2735
- dtype = getattr (attrs , "value_type" , None )
2747
+ dtype = getattr (attrs , "value_type" , dtype )
2736
2748
shape = getattr (attrs , "shape" , None )
2737
2749
2738
2750
if shape is not None :
@@ -2754,7 +2766,8 @@ def read_array(self, key, start=None, stop=None):
2754
2766
raise NotImplementedError (
2755
2767
"start and/or stop are not supported in fixed Sparse reading"
2756
2768
)
2757
- sp_index = self .read_index ("{}_sp_index" .format (key ))
2769
+ if sp_index is None :
2770
+ sp_index = self .read_index ("{}_sp_index" .format (key ))
2758
2771
ret = SparseArray (
2759
2772
ret , sparse_index = sp_index , fill_value = self .attrs .fill_value
2760
2773
)
@@ -3079,10 +3092,10 @@ def shape(self):
3079
3092
except (TypeError , AttributeError ):
3080
3093
return None
3081
3094
3082
- def read (self , ** kwargs ):
3095
+ def read (self , key = "values" , ** kwargs ):
3083
3096
kwargs = self .validate_read (kwargs )
3084
3097
index = self .read_index ("index" , ** kwargs )
3085
- values = self .read_array ("values" , ** kwargs )
3098
+ values = self .read_array (key , ** kwargs )
3086
3099
return Series (values , index = index , name = self .name )
3087
3100
3088
3101
def write (self , obj , ** kwargs ):
@@ -3184,6 +3197,22 @@ class FrameFixed(BlockManagerFixed):
3184
3197
obj_type = DataFrame
3185
3198
3186
3199
3200
+ class SparseFrameFixed (GenericFixed ):
3201
+ pandas_kind = "sparse_frame"
3202
+ attributes = ["default_kind" , "default_fill_value" ]
3203
+
3204
+ def read (self , ** kwargs ):
3205
+ kwargs = self .validate_read (kwargs )
3206
+ columns = self .read_index ("columns" )
3207
+ sdict = {}
3208
+ for c in columns :
3209
+ key = "sparse_series_{columns}" .format (columns = c )
3210
+ s = SeriesFixed (self .parent , getattr (self .group , key ))
3211
+ s .infer_axes ()
3212
+ sdict [c ] = s .read (key = key )
3213
+ return DataFrame (sdict )
3214
+
3215
+
3187
3216
class Table (Fixed ):
3188
3217
""" represent a table:
3189
3218
facilitate read/write of various types of tables
0 commit comments