Skip to content

Commit 397012d

Browse files
committed
added engine argument to the read_hdf method and all to_hdf methods
1 parent 18f0e77 commit 397012d

File tree

4 files changed

+23
-11
lines changed

4 files changed

+23
-11
lines changed

larray/core/array.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6701,7 +6701,7 @@ def to_csv(self, filepath, sep=',', na_rep='', wide=True, value_name='value', dr
67016701
series = self.to_series(value_name, dropna is not None)
67026702
series.to_csv(filepath, sep=sep, na_rep=na_rep, header=True, **kwargs)
67036703

6704-
def to_hdf(self, filepath, key):
6704+
def to_hdf(self, filepath, key, engine='auto'):
67056705
r"""
67066706
Writes array to a HDF file.
67076707
@@ -6714,6 +6714,9 @@ def to_hdf(self, filepath, key):
67146714
Path where the hdf file has to be written.
67156715
key : str or Group
67166716
Key (path) of the array within the HDF file (see Notes below).
6717+
engine: {'auto', 'tables', 'pandas'}, optional
6718+
Dump using `engine`. Use 'pandas' to update an HDF file generated with a LArray version previous to 0.31.
6719+
Defaults to 'auto' (use default engine if you don't know the LArray version used to produced the HDF file).
67176720
67186721
Notes
67196722
-----
@@ -6735,7 +6738,7 @@ def to_hdf(self, filepath, key):
67356738
>>> a.to_hdf('test.h5', 'arrays/a') # doctest: +SKIP
67366739
"""
67376740
from larray.inout.hdf import LHDFStore
6738-
with LHDFStore(filepath) as store:
6741+
with LHDFStore(filepath, engine=engine) as store:
67396742
store.put(key, self)
67406743

67416744
def to_stata(self, filepath_or_buffer, **kwargs):

larray/core/axis.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1304,7 +1304,7 @@ def align(self, other, join='outer'):
13041304
else:
13051305
return self
13061306

1307-
def to_hdf(self, filepath, key=None):
1307+
def to_hdf(self, filepath, key=None, engine='auto'):
13081308
r"""
13091309
Writes axis to a HDF file.
13101310
@@ -1319,6 +1319,9 @@ def to_hdf(self, filepath, key=None):
13191319
Key (path) of the axis within the HDF file (see Notes below).
13201320
If None, the name of the axis is used.
13211321
Defaults to None.
1322+
engine: {'auto', 'tables', 'pandas'}, optional
1323+
Dump using `engine`. Use 'pandas' to update an HDF file generated with a LArray version previous to 0.31.
1324+
Defaults to 'auto' (use default engine if you don't know the LArray version used to produced the HDF file).
13221325
13231326
Notes
13241327
-----
@@ -1349,7 +1352,7 @@ def to_hdf(self, filepath, key=None):
13491352
if self.name is None:
13501353
raise ValueError("Argument key must be provided explicitly in case of anonymous axis")
13511354
key = self.name
1352-
with LHDFStore(filepath) as store:
1355+
with LHDFStore(filepath, engine=engine) as store:
13531356
store.put(key, self)
13541357

13551358
@property

larray/core/group.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1396,7 +1396,7 @@ def containing(self, substring):
13961396
substring = substring.eval()
13971397
return LGroup([v for v in self.eval() if substring in v], axis=self.axis)
13981398

1399-
def to_hdf(self, filepath, key=None, axis_key=None):
1399+
def to_hdf(self, filepath, key=None, axis_key=None, engine='auto'):
14001400
r"""
14011401
Writes group to a HDF file.
14021402
@@ -1417,6 +1417,9 @@ def to_hdf(self, filepath, key=None, axis_key=None):
14171417
Key (path) of the associated axis in the HDF file (see Notes below).
14181418
If None, the name of the axis associated with the group is used.
14191419
Defaults to None.
1420+
engine: {'auto', 'tables', 'pandas'}, optional
1421+
Dump using `engine`. Use 'pandas' to update an HDF file generated with a LArray version previous to 0.31.
1422+
Defaults to 'auto' (use default engine if you don't know the LArray version used to produced the HDF file).
14201423
14211424
Notes
14221425
-----
@@ -1458,7 +1461,7 @@ def to_hdf(self, filepath, key=None, axis_key=None):
14581461
if self.name is None:
14591462
raise ValueError("Argument key must be provided explicitly in case of anonymous group")
14601463
key = self.name
1461-
with LHDFStore(filepath) as store:
1464+
with LHDFStore(filepath, engine=engine) as store:
14621465
store.put(key, self, axis_key=axis_key)
14631466

14641467
# this makes range(LGroup(int)) possible

larray/inout/hdf.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ class LHDFStore(object):
346346
Parameters
347347
----------
348348
filepath : str or PathLike object
349-
File path to HDF5 file
349+
File path to HDF5 file.
350350
mode : {'a', 'w', 'r', 'r+'}, default 'a'
351351
352352
``'r'``
@@ -562,13 +562,13 @@ def put(self, key, value, **kwargs):
562562

563563

564564
def read_hdf(filepath_or_buffer, key, fill_value=nan, na=nan, sort_rows=False, sort_columns=False,
565-
name=None, **kwargs):
565+
name=None, engine='auto', **kwargs):
566566
r"""Reads an axis or group or array named key from a HDF5 file in filepath (path+name)
567567
568568
Parameters
569569
----------
570-
filepath_or_buffer : str or LArrayHDFStore
571-
Path and name where the HDF5 file is stored or a HDFStore object.
570+
filepath_or_buffer : str or PathLike object
571+
Path and name where the HDF5 file is stored.
572572
key : str or Group
573573
Name of the object to read.
574574
fill_value : scalar or LArray, optional
@@ -585,6 +585,9 @@ def read_hdf(filepath_or_buffer, key, fill_value=nan, na=nan, sort_rows=False, s
585585
name : str, optional
586586
Name of the axis or group to return. If None, name is set to passed key.
587587
Defaults to None.
588+
engine: {'auto', 'tables', 'pandas'}, optional
589+
Load using `engine`. Use 'pandas' to read an HDF file generated with a LArray version previous to 0.31.
590+
Defaults to 'auto' (use default engine if you don't know the LArray version used to produced the HDF file).
588591
589592
Returns
590593
-------
@@ -610,7 +613,7 @@ def read_hdf(filepath_or_buffer, key, fill_value=nan, na=nan, sort_rows=False, s
610613
fill_value = na
611614
warnings.warn("read_hdf `na` argument has been renamed to `fill_value`. Please use that instead.",
612615
FutureWarning, stacklevel=2)
613-
with LHDFStore(filepath_or_buffer, **kwargs) as store:
616+
with LHDFStore(filepath_or_buffer, engine=engine, **kwargs) as store:
614617
res = store.get(key, fill_value=fill_value, sort_rows=sort_rows, sort_columns=sort_columns, name=name)
615618
return res
616619

0 commit comments

Comments
 (0)