Skip to content

Commit

Permalink
🐛 apply new read-convert everywhere...
Browse files Browse the repository at this point in the history
  • Loading branch information
niklassiemer committed Nov 18, 2021
1 parent 9253669 commit 5adccd9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 2 additions & 0 deletions pyiron_base/generic/hdfio.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ def __getitem__(self, item):
# check whether the data is there and 1 to read it) and increases in the worst case from 1 to 2 (1 to
# try to read it here and one more time to verify it's not a group below).
obj = h5io.read_hdf5(self.file_name, title=self._get_h5_path(item))
if self._is_convertable_dtype_object_array(obj):
obj = self._convert_dtype_obj_array(obj.copy())
return obj
except (ValueError, OSError):
# h5io couldn't find a dataset with name item, but there still might be a group with that name, which we
Expand Down
8 changes: 5 additions & 3 deletions tests/generic/test_fileHDFio.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def test_array_type_conversion(self):
array = hdf['object_array_with_lists']
np.array_equal(array, object_array_with_lists)
self.assertIsInstance(array, np.ndarray)
self.assertTrue(array.dtype == np.dtype(object))
self.assertEqual(array.dtype, np.dtype(object), msg="dtype=object array falsely converted.")

# Here I got: TypeError: Object dtype dtype('O') has no native HDF5 equivalent
#
Expand All @@ -170,13 +170,15 @@ def test_array_type_conversion(self):
array = hdf['int_array_as_objects_array']
np.array_equal(array, int_array_as_objects_array)
self.assertIsInstance(array, np.ndarray)
self.assertTrue(array.dtype == np.dtype(int))
self.assertEqual(array.dtype, np.dtype(int), msg=f"dtype=object array containing only int not converted "
f"to dtype int array.")

with self.subTest('float_array_as_objects_array'):
array = hdf['float_array_as_objects_array']
np.array_equal(array, float_array_as_objects_array)
self.assertIsInstance(array, np.ndarray)
self.assertTrue(array.dtype == np.dtype(float))
self.assertEqual(array.dtype, np.dtype(float), msg=f"dtype=object array containing only float not converted"
f" to dtype float array.")

hdf.remove_group()

Expand Down

0 comments on commit 5adccd9

Please sign in to comment.