17
17
18
18
@timed_debug
19
19
def read_dataframe (filename , index_col = None , columns = None , parse_dates = False , ** kwargs ):
20
- """Convert filename to a dataframe. Supports .csv, .json, .feather, .h5 .
20
+ """Convert filename to a dataframe. Supports .csv, .json, .feather.
21
21
Handles compressed files.
22
22
23
23
Parameters
@@ -64,11 +64,13 @@ def read_dataframe(filename, index_col=None, columns=None, parse_dates=False, **
64
64
needs_new_index = True
65
65
with open_func (filename , "rb" ) as f_in :
66
66
df = pd .read_feather (f_in , ** kwargs )
67
- elif ext == ".h5" :
68
- # This assumes that the file has a single dataframe, and so the
69
- # key name is not relevant.
70
- df = pd .read_hdf (filename , ** kwargs )
71
- needs_new_index = True
67
+ # This requires the pytables library which is painful to install on many platforms.
68
+ # Disable for now because the functionality isn't worth it.
69
+ # elif ext == ".h5":
70
+ # # This assumes that the file has a single dataframe, and so the
71
+ # # key name is not relevant.
72
+ # df = pd.read_hdf(filename, **kwargs)
73
+ # needs_new_index = True
72
74
else :
73
75
raise InvalidParameter (f"unsupported file extension { ext } " )
74
76
@@ -184,13 +186,10 @@ def read_dataframes_by_substrings(
184
186
def write_dataframe (df , file_path , compress = False , keep_original = False , ** kwargs ):
185
187
"""Write the dataframe to a file with in a format matching the extension.
186
188
187
- Note that the feather and h5 formats do not support row indices.
189
+ Note that the feather formats do not support row indices.
188
190
Index columns will be lost for those formats. If the dataframe has an index
189
191
then it should be converted to a column before calling this function.
190
192
191
- This function only supports storing a single dataframe inside an HDF5 file.
192
- It always uses the key 'data'.
193
-
194
193
Parameters
195
194
----------
196
195
df : pd.DataFrame
@@ -216,15 +215,16 @@ def write_dataframe(df, file_path, compress=False, keep_original=False, **kwargs
216
215
df .to_csv (file_path , ** kwargs )
217
216
elif ext == ".feather" :
218
217
df .to_feather (file_path , ** kwargs )
219
- elif ext == ".h5" :
220
- # HDF5 supports built-in compression, levels 1-9
221
- if "complevel" in kwargs :
222
- complevel = kwargs ["complevel" ]
223
- elif compress :
224
- complevel = 9
225
- else :
226
- complevel = 0
227
- df .to_hdf (file_path , "data" , mode = "w" , complevel = complevel , ** kwargs )
218
+ # See note above regarding pytables dependency.
219
+ # elif ext == ".h5":
220
+ # # HDF5 supports built-in compression, levels 1-9
221
+ # if "complevel" in kwargs:
222
+ # complevel = kwargs["complevel"]
223
+ # elif compress:
224
+ # complevel = 9
225
+ # else:
226
+ # complevel = 0
227
+ # df.to_hdf(file_path, "data", mode="w", complevel=complevel, **kwargs)
228
228
elif ext == ".json" :
229
229
df .to_json (file_path , ** kwargs )
230
230
else :
0 commit comments