From 5a71f299a54aa50a272152bf85687c3e4277d536 Mon Sep 17 00:00:00 2001 From: ppinchuk Date: Fri, 11 Jul 2025 15:43:00 -0600 Subject: [PATCH 1/5] Bump version --- rex/version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rex/version.py b/rex/version.py index 1503ecad2..d32596b8a 100644 --- a/rex/version.py +++ b/rex/version.py @@ -1,3 +1,3 @@ """rex Version number""" -__version__ = "0.4.2" +__version__ = "0.4.3" From 53d570e56433395c226348b3c80ba6c68258d3e2 Mon Sep 17 00:00:00 2001 From: ppinchuk Date: Fri, 11 Jul 2025 15:52:09 -0600 Subject: [PATCH 2/5] Don't overwrite existing attributes --- rex/outputs.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/rex/outputs.py b/rex/outputs.py index 0b50528c3..a586bc773 100644 --- a/rex/outputs.py +++ b/rex/outputs.py @@ -209,10 +209,13 @@ def full_version_record(self): def set_version_attr(self): """Set the version attribute to the h5 file.""" - self.h5.attrs['version'] = __version__ - self.h5.attrs['full_version_record'] = json.dumps( - self.full_version_record) - self.h5.attrs['package'] = 'rex' + new_attrs = {'version': __version__, + 'full_version_record': json.dumps( + self.full_version_record), + 'package': 'rex'} + for name, value in new_attrs.items(): + if name not in self.h5.attrs: + self.h5.attrs[name] = value @property def version(self): From 14548425f34e97cfcc423b8d42cb359f0b4103f6 Mon Sep 17 00:00:00 2001 From: ppinchuk Date: Fri, 11 Jul 2025 15:52:18 -0600 Subject: [PATCH 3/5] Add outputs test --- tests/test_outputs.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/test_outputs.py b/tests/test_outputs.py index 76f5f3d65..4f0948610 100644 --- a/tests/test_outputs.py +++ b/tests/test_outputs.py @@ -253,6 +253,23 @@ def test_1D_dataset_shape(): assert res['dset3'].shape == (8760,) +def test_attrs_multiple_opens(): + """Test that attrs are not overwritten on multiple opens""" + + attrs_to_test = ["package", "version", "full_version_record"] + with tempfile.TemporaryDirectory() as td: + fp = os.path.join(td, 'outputs.h5') + with Outputs(fp, 'a') as f: + for attr in attrs_to_test: + assert f.h5.attrs[attr] != "test" + f.h5.attrs[attr] = "test" + assert f.h5.attrs[attr] == "test" + + with Outputs(fp, 'a') as f: + for attr in attrs_to_test: + assert f.h5.attrs["package"] == "test" + + def execute_pytest(capture='all', flags='-rapP'): """Execute module as pytest with detailed summary report. From 37ea7861eaba998d307210d8005d695d5797efae Mon Sep 17 00:00:00 2001 From: ppinchuk Date: Fri, 11 Jul 2025 15:54:47 -0600 Subject: [PATCH 4/5] Re-order attrs --- rex/outputs.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/rex/outputs.py b/rex/outputs.py index a586bc773..f1f5cb6e2 100644 --- a/rex/outputs.py +++ b/rex/outputs.py @@ -196,14 +196,14 @@ def full_version_record(self): dict Dictionary of package versions for dependencies """ - versions = {'rex': __version__, + versions = {'python': sys.version, + 'rex': __version__, + 'h5py': h5py.__version__, + 'h5pyd': h5pyd.__version__, 'pandas': pd.__version__, 'numpy': np.__version__, - 'python': sys.version, + 'scipy': scipy.__version__, 'click': click.__version__, - 'h5py': h5py.__version__, - 'h5pyd': h5pyd.__version__, - 'scipy': scipy.__version__ } return versions From 96c9f4029c9be69e2f31e07069b3d526a9044411 Mon Sep 17 00:00:00 2001 From: ppinchuk Date: Fri, 11 Jul 2025 16:01:08 -0600 Subject: [PATCH 5/5] Linter fixes --- rex/outputs.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/rex/outputs.py b/rex/outputs.py index f1f5cb6e2..ba78a412a 100644 --- a/rex/outputs.py +++ b/rex/outputs.py @@ -211,7 +211,7 @@ def set_version_attr(self): """Set the version attribute to the h5 file.""" new_attrs = {'version': __version__, 'full_version_record': json.dumps( - self.full_version_record), + self.full_version_record), 'package': 'rex'} for name, value in new_attrs.items(): if name not in self.h5.attrs: @@ -571,7 +571,7 @@ def _check_chunks(self, chunks, data=None): msg = ('Shape dimensions ({}) are not the same length as chunks ' '({}). Please provide a single chunk value for each ' 'dimension!' - .format(shape, chunks)) + .format(shape, chunks)) logger.error(msg) raise HandlerRuntimeError(msg) @@ -751,6 +751,7 @@ def update_dset(self, dset, dset_array, dset_slice=None): keys = (dset, ) + dset_slice + # pylint: disable=unnecessary-dunder-call arr = self.__getitem__(keys) if not np.array_equal(arr, dset_array): self._set_ds_array(dset, dset_array, dset_slice)