Skip to content

Commit

Permalink
fix #702 : fixed bug when writing metadata using HDF format
Browse files Browse the repository at this point in the history
  • Loading branch information
alixdamman committed May 10, 2019
1 parent af61c52 commit 01669f2
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 9 deletions.
4 changes: 4 additions & 0 deletions doc/source/changes/version_0_30.rst.inc
Original file line number Diff line number Diff line change
Expand Up @@ -285,3 +285,7 @@ Fixes
of the API Reference (closes :issue:`698`).

* fixed arithmetic operations between two sessions returning a nan value for each axis and group (closes :issue:`725`).

* fixed dumping sessions with metadata in HDF format (closes :issue:`702`).

* fixed minimum version of pandas to install. The minimum version is now 0.20.0.
14 changes: 9 additions & 5 deletions larray/core/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,15 @@ def _convert_value(value):
return Metadata([(key, _convert_value(value)) for key, value in zip(array.axes.labels[0], array.data)])

# ---------- IO methods ----------
def to_hdf(self, hdfstore, key):
def to_hdf(self, hdfstore, key=None):
if len(self):
hdfstore.get_storer(key).attrs.metadata = self
attrs = hdfstore.get_storer(key).attrs if key is not None else hdfstore.root._v_attrs
attrs.metadata = self

@classmethod
def from_hdf(cls, hdfstore, key):
if 'metadata' in hdfstore.get_storer(key).attrs:
return hdfstore.get_storer(key).attrs.metadata
def from_hdf(cls, hdfstore, key=None):
attrs = hdfstore.get_storer(key).attrs if key is not None else hdfstore.root._v_attrs
if 'metadata' in attrs:
return attrs.metadata
else:
return None
8 changes: 5 additions & 3 deletions larray/inout/hdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,13 @@ def _dump_item(self, key, value, *args, **kwargs):
raise TypeError()

def _read_metadata(self):
attrs = self.handle.get_node('')._v_attrs
return attrs.metadata if 'metadata' in attrs else Metadata()
metadata = Metadata.from_hdf(self.handle)
if metadata is None:
metadata = Metadata()
return metadata

def _dump_metadata(self, metadata):
self.handle.get_node('')._v_attrs.metadata = metadata
metadata.to_hdf(self.handle)

def close(self):
self.handle.close()
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def readlocal(fname):
LONG_DESCRIPTION = readlocal("README.rst")
SETUP_REQUIRES = []
# excludes numpy 1.16.* because it is incompatible with pytables < 3.5
INSTALL_REQUIRES = ['numpy >= 1.13, != 1.16.*', 'pandas >= 0.13.1']
INSTALL_REQUIRES = ['numpy >= 1.13, != 1.16.*', 'pandas >= 0.20.0']
TESTS_REQUIRE = ['pytest', 'pytest-pep8']

LICENSE = 'GPLv3'
Expand Down

0 comments on commit 01669f2

Please sign in to comment.