@@ -201,6 +201,46 @@ def test_unpack_hdf5_nested_dict_group_path(tmp_path: Path) -> None:
201201 np .testing .assert_equal (result , expected )
202202
203203
204+ def test_unpack_hdf5_list_of_bytes (tmp_path : Path ) -> None :
205+ """Test loading a list of strings which are encoded to Numpy array on saving."""
206+ to_save = {
207+ "config" : {
208+ "grainstats" : {
209+ "class_names" : np .asarray ([b"DNA" , b"Protein" ], dtype = "S7" ),
210+ "edge_detection_method" : "binary_erosion" ,
211+ "extract_height_profile" : True ,
212+ "run" : True ,
213+ }
214+ }
215+ }
216+ group_path = "/config/grainstats/"
217+ expected = {
218+ "class_names" : np .asarray ([b"DNA" , b"Protein" ], dtype = "S7" ),
219+ "edge_detection_method" : "binary_erosion" ,
220+ "extract_height_profile" : True ,
221+ "run" : True ,
222+ }
223+ # Manually save the dictionary to HDF5 format
224+ with h5py .File (tmp_path / "hdf5_file_list_of_strings" , "w" ) as f :
225+ # t_path = Path.cwd()
226+ # with h5py.File(t_path / "tmp" / "something_else", "w") as f:
227+ config = f .create_group ("config" )
228+ grainstats = config .create_group ("grainstats" )
229+ grainstats .create_dataset ("class_names" , data = to_save ["config" ]["grainstats" ]["class_names" ])
230+ grainstats .create_dataset (
231+ "edge_detection_method" , data = to_save ["config" ]["grainstats" ]["edge_detection_method" ]
232+ )
233+ grainstats .create_dataset (
234+ "extract_height_profile" , data = to_save ["config" ]["grainstats" ]["extract_height_profile" ]
235+ )
236+ grainstats .create_dataset ("run" , data = to_save ["config" ]["grainstats" ]["run" ])
237+
238+ # Load it back in and check if the list is the same
239+ with h5py .File (tmp_path / "hdf5_file_list_of_strings" , "r" ) as f :
240+ result = unpack_hdf5 (open_hdf5_file = f , group_path = group_path )
241+ np .testing .assert_equal (result , expected )
242+
243+
204244def test_read_yaml () -> None :
205245 """Test reading of YAML file."""
206246 sample_config = read_yaml (RESOURCES / "test.yaml" )
0 commit comments