Skip to content

Commit 7db7001

Browse files
authored
Merge pull request #536 from jgrewe/str_handling
Keep string data as python str
2 parents 1ea15e4 + d969bd0 commit 7db7001

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

nixio/hdf5/h5dataset.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def read_data(self, slc=None):
6161
# Let's change it to IndexError
6262
raise IndexError(te_exc)
6363
if data.dtype == util.vlen_str_dtype:
64-
data = np.reshape(np.array(list(map(ensure_str, data.ravel()))), data.shape)
64+
data = np.reshape(np.array(list(map(ensure_str, data.ravel())), dtype=object), data.shape)
6565
elif data.dtype.fields:
6666
data = self._convert_string_cols(data)
6767
return data

nixio/hdf5/h5group.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,8 @@ def set_attr(self, name, value):
250250
if name in self.group.attrs:
251251
del self.group.attrs[name]
252252
else:
253+
if isinstance(value, np.str_):
254+
value = str(value)
253255
self.group.attrs[name] = value
254256

255257
def get_attr(self, name):

nixio/test/test_data_view.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,13 @@ def test_data_view_read_2d_str_array(self):
4242
da = self.file.blocks[0].create_data_array("str_2d_array", "test", dtype=nix.DataType.String, data=data)
4343
da.append_set_dimension()
4444
da.append_set_dimension()
45-
45+
4646
dv = da.get_slice((0, 0), extents=(10, 4))
4747
npeq = np.testing.assert_equal
4848
npeq(dv.shape, da.shape)
4949
npeq(dv[:], data)
50+
for d in dv[:]:
51+
assert("numpy.str_" not in str(type(d)))
5052

5153
def test_data_view_fancy_slicing(self):
5254
da = self.file.blocks[0].data_arrays[0]

0 commit comments

Comments
 (0)