Skip to content

Commit fa1c222

Browse files
committed
added doctests for LHDFStore + updated LHDFStore.summary() method
1 parent 397012d commit fa1c222

File tree

1 file changed

+35
-8
lines changed

1 file changed

+35
-8
lines changed

larray/inout/hdf.py

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,33 @@ class LHDFStore(object):
372372
373373
Examples
374374
--------
375-
# TODO : write examples
375+
>>> from larray import ndtest
376+
>>> with LHDFStore('hdf_file.h5') as s:
377+
... # dump and read an axis
378+
... s['a'] = Axis("a=a0..a2")
379+
... a = s['a']
380+
... # dump and read a group
381+
... s['a01'] = a['a0,a1'] >> 'a01'
382+
... a01 = s['a01']
383+
... # dump and read an array
384+
... s['arr'] = ndtest((3, 3))
385+
... arr = s['arr']
386+
... # add and read top level metadata
387+
... s.meta.author = 'John Smith'
388+
... metadata = s.meta
389+
... # get filepath
390+
... s.filename
391+
... # display list of items stored in the hdf file
392+
... s.keys()
393+
... # display list of items and their type
394+
... print(s.summary())
395+
'hdf_file.h5'
396+
['/a', '/a01', '/arr', '/arr/axis_a', '/arr/axis_b']
397+
/a: Axis
398+
/a01: Group
399+
/arr: Array
400+
/arr/axis_a: Axis
401+
/arr/axis_b: Axis
376402
"""
377403
def __init__(self, filepath, mode=None, complevel=None, complib=None,
378404
fletcher32=False, engine='auto', **kwargs):
@@ -475,6 +501,10 @@ def keys(self):
475501
Return a (potentially unordered) list of the keys corresponding to the
476502
objects stored in the HDFStore. These are ABSOLUTE path-names (e.g.
477503
have the leading '/'
504+
505+
See Also
506+
--------
507+
LHDFStore
478508
"""
479509
return [n._v_pathname for n in self._storer.groups()]
480510

@@ -494,16 +524,13 @@ def summary(self):
494524
"""
495525
Return a list of LArray stored in the HDF5 file.
496526
497-
Examples
527+
See Also
498528
--------
499-
TODO: write examples
529+
LHDFStore
500530
"""
501531
if self.is_open:
502-
res = ""
503-
for name, group in self.items():
504-
_type = getattr(group._v_attrs, 'type', 'Unknown')
505-
res += "{}: {}\n".format(name, _type)
506-
return res
532+
return '\n'.join(["{}: {}".format(name, getattr(group._v_attrs, 'type', 'Unknown'))
533+
for name, group in self.items()])
507534
else:
508535
return "File {} is CLOSED".format(self.filename)
509536

0 commit comments

Comments
 (0)