mirror of
https://github.com/p2p-ld/numpydantic.git
synced 2024-11-12 17:54:29 +00:00
correct decoding of byte arrays
This commit is contained in:
parent
f28c766b96
commit
e78c170a2b
2 changed files with 8 additions and 7 deletions
|
@ -130,7 +130,10 @@ class H5Proxy:
|
|||
else:
|
||||
item = (item, self.field)
|
||||
|
||||
return obj[item].decode(encoding.encoding)
|
||||
try:
|
||||
return obj[item].decode(encoding.encoding)
|
||||
except AttributeError:
|
||||
return np.strings.decode(obj[item], encoding=encoding.encoding)
|
||||
else:
|
||||
obj = obj.fields(self.field)
|
||||
else:
|
||||
|
@ -262,12 +265,7 @@ class H5Interface(Interface):
|
|||
|
||||
Subclasses to correctly handle
|
||||
"""
|
||||
if hasattr(array.dtype, "type") and array.dtype.type is np.object_:
|
||||
if h5py.h5t.check_string_dtype(array.dtype):
|
||||
return str
|
||||
else:
|
||||
return self.get_object_dtype(array)
|
||||
elif h5py.h5t.check_string_dtype(array.dtype):
|
||||
if h5py.h5t.check_string_dtype(array.dtype):
|
||||
return str
|
||||
else:
|
||||
return array.dtype
|
||||
|
|
|
@ -171,3 +171,6 @@ def test_strings(hdf5_array, compound):
|
|||
instance.array[0, 0] = "hey"
|
||||
assert instance.array[0, 0] == "hey"
|
||||
assert isinstance(instance.array[0, 1], str)
|
||||
|
||||
instance.array[1] = "sup"
|
||||
assert all(instance.array[1] == "sup")
|
||||
|
|
Loading…
Reference in a new issue