correct decoding of byte arrays

This commit is contained in:
sneakers-the-rat 2024-09-02 22:49:13 -07:00
parent f28c766b96
commit e78c170a2b
Signed by untrusted user who does not match committer: jonny
GPG key ID: 6DCB96EF1E4D232D
2 changed files with 8 additions and 7 deletions

View file

@ -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

View file

@ -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")