mirror of
https://github.com/p2p-ld/numpydantic.git
synced 2024-11-14 02:34:28 +00:00
strings in compound dtypes
This commit is contained in:
parent
0f1e0d0caf
commit
f28c766b96
2 changed files with 10 additions and 4 deletions
|
@ -124,8 +124,13 @@ class H5Proxy:
|
||||||
with h5py.File(self.file, "r") as h5f:
|
with h5py.File(self.file, "r") as h5f:
|
||||||
obj = h5f.get(self.path)
|
obj = h5f.get(self.path)
|
||||||
if self.field is not None:
|
if self.field is not None:
|
||||||
if h5py.h5t.check_string_dtype(obj.dtype[self.field]):
|
if encoding := h5py.h5t.check_string_dtype(obj.dtype[self.field]):
|
||||||
obj = obj.fields(self.field).asstr()
|
if isinstance(item, tuple):
|
||||||
|
item = (*item, self.field)
|
||||||
|
else:
|
||||||
|
item = (item, self.field)
|
||||||
|
|
||||||
|
return obj[item].decode(encoding.encoding)
|
||||||
else:
|
else:
|
||||||
obj = obj.fields(self.field)
|
obj = obj.fields(self.field)
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -157,11 +157,12 @@ def test_compound_dtype(tmp_path):
|
||||||
assert all(instance.array[1] == 2)
|
assert all(instance.array[1] == 2)
|
||||||
|
|
||||||
|
|
||||||
def test_strings(hdf5_array):
|
@pytest.mark.parametrize("compound", [True, False])
|
||||||
|
def test_strings(hdf5_array, compound):
|
||||||
"""
|
"""
|
||||||
HDF5 proxy can get and set strings just like any other dtype
|
HDF5 proxy can get and set strings just like any other dtype
|
||||||
"""
|
"""
|
||||||
array = hdf5_array((10, 10), str)
|
array = hdf5_array((10, 10), str, compound=compound)
|
||||||
|
|
||||||
class MyModel(BaseModel):
|
class MyModel(BaseModel):
|
||||||
array: NDArray[Shape["10, 10"], str]
|
array: NDArray[Shape["10, 10"], str]
|
||||||
|
|
Loading…
Reference in a new issue