fix setting values

This commit is contained in:
sneakers-the-rat 2024-09-02 17:05:32 -07:00
parent 290a72f8ca
commit 2a93694cfc
Signed by untrusted user who does not match committer: jonny
GPG key ID: 6DCB96EF1E4D232D
2 changed files with 14 additions and 3 deletions

View file

@ -112,9 +112,13 @@ class H5Proxy:
):
with h5py.File(self.file, "r+", locking=True) as h5f:
obj = h5f.get(self.path)
if self.field is not None:
obj = obj.fields(self.field)
if self.field is None:
obj[key] = value
else:
if isinstance(key, tuple):
obj[*key, self.field] = value
else:
obj[key, self.field] = value
def open(self, mode: str = "r") -> "h5py.Dataset":
"""

View file

@ -150,3 +150,10 @@ def test_compound_dtype(tmp_path):
assert instance.array.dtype == np.dtype("int64")
assert instance.array.shape == (10, 20)
assert instance.array[0, 0] == 0
# set values too
instance.array[0, :] = 1
assert all(instance.array[0, :] == 1)
assert all(instance.array[1, :] == 0)
instance.array[1] = 2
assert all(instance.array[1] == 2)