Skip to content

Commit

Permalink
added doctests for LHDFStore + updated LHDFStore.summary() method
Browse files Browse the repository at this point in the history
  • Loading branch information
alixdamman committed Aug 26, 2019
1 parent 397012d commit fa1c222
Showing 1 changed file with 35 additions and 8 deletions.
43 changes: 35 additions & 8 deletions larray/inout/hdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,33 @@ class LHDFStore(object):
Examples
--------
# TODO : write examples
>>> from larray import ndtest
>>> with LHDFStore('hdf_file.h5') as s:
... # dump and read an axis
... s['a'] = Axis("a=a0..a2")
... a = s['a']
... # dump and read a group
... s['a01'] = a['a0,a1'] >> 'a01'
... a01 = s['a01']
... # dump and read an array
... s['arr'] = ndtest((3, 3))
... arr = s['arr']
... # add and read top level metadata
... s.meta.author = 'John Smith'
... metadata = s.meta
... # get filepath
... s.filename
... # display list of items stored in the hdf file
... s.keys()
... # display list of items and their type
... print(s.summary())
'hdf_file.h5'
['/a', '/a01', '/arr', '/arr/axis_a', '/arr/axis_b']
/a: Axis
/a01: Group
/arr: Array
/arr/axis_a: Axis
/arr/axis_b: Axis
"""
def __init__(self, filepath, mode=None, complevel=None, complib=None,
fletcher32=False, engine='auto', **kwargs):
Expand Down Expand Up @@ -475,6 +501,10 @@ def keys(self):
Return a (potentially unordered) list of the keys corresponding to the
objects stored in the HDFStore. These are ABSOLUTE path-names (e.g.
have the leading '/'
See Also
--------
LHDFStore
"""
return [n._v_pathname for n in self._storer.groups()]

Expand All @@ -494,16 +524,13 @@ def summary(self):
"""
Return a list of LArray stored in the HDF5 file.
Examples
See Also
--------
TODO: write examples
LHDFStore
"""
if self.is_open:
res = ""
for name, group in self.items():
_type = getattr(group._v_attrs, 'type', 'Unknown')
res += "{}: {}\n".format(name, _type)
return res
return '\n'.join(["{}: {}".format(name, getattr(group._v_attrs, 'type', 'Unknown'))
for name, group in self.items()])
else:
return "File {} is CLOSED".format(self.filename)

Expand Down

0 comments on commit fa1c222

Please sign in to comment.