mirror of
https://github.com/p2p-ld/numpydantic.git
synced 2025-01-10 05:54:26 +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:
|
else:
|
||||||
item = (item, self.field)
|
item = (item, self.field)
|
||||||
|
|
||||||
|
try:
|
||||||
return obj[item].decode(encoding.encoding)
|
return obj[item].decode(encoding.encoding)
|
||||||
|
except AttributeError:
|
||||||
|
return np.strings.decode(obj[item], encoding=encoding.encoding)
|
||||||
else:
|
else:
|
||||||
obj = obj.fields(self.field)
|
obj = obj.fields(self.field)
|
||||||
else:
|
else:
|
||||||
|
@ -262,13 +265,8 @@ class H5Interface(Interface):
|
||||||
|
|
||||||
Subclasses to correctly handle
|
Subclasses to correctly handle
|
||||||
"""
|
"""
|
||||||
if hasattr(array.dtype, "type") and array.dtype.type is np.object_:
|
|
||||||
if h5py.h5t.check_string_dtype(array.dtype):
|
if h5py.h5t.check_string_dtype(array.dtype):
|
||||||
return str
|
return str
|
||||||
else:
|
|
||||||
return self.get_object_dtype(array)
|
|
||||||
elif h5py.h5t.check_string_dtype(array.dtype):
|
|
||||||
return str
|
|
||||||
else:
|
else:
|
||||||
return array.dtype
|
return array.dtype
|
||||||
|
|
||||||
|
|
|
@ -171,3 +171,6 @@ def test_strings(hdf5_array, compound):
|
||||||
instance.array[0, 0] = "hey"
|
instance.array[0, 0] = "hey"
|
||||||
assert instance.array[0, 0] == "hey"
|
assert instance.array[0, 0] == "hey"
|
||||||
assert isinstance(instance.array[0, 1], str)
|
assert isinstance(instance.array[0, 1], str)
|
||||||
|
|
||||||
|
instance.array[1] = "sup"
|
||||||
|
assert all(instance.array[1] == "sup")
|
||||||
|
|
Loading…
Reference in a new issue