Skip to content

Commit

Permalink
allow saving None
Browse files Browse the repository at this point in the history
  • Loading branch information
segasai committed Nov 16, 2024
1 parent e1df501 commit 8680526
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions py/rvspecfit/serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ def recursively_save_dict_contents_to_group(h5file,
key_path,
item,
allow_pickle=allow_pickle)
elif item is None:
h5file.create_dataset(key_path, data=0)
h5file[key_path].attrs['type'] = 'None'
elif isinstance(item, (list, tuple)):
is_list = isinstance(item, list)
if all(isinstance(x, type(item[0]))
Expand Down Expand Up @@ -121,6 +124,8 @@ def recursively_load_dict_contents_from_group(h5file, path):
ans[key] = item[()]
elif item.attrs['type'] == 'pickle':
ans[key] = pickle.loads(item[()])
elif item.attrs['type'] == 'None':
ans[key] = None
else:
raise Exception('unsupported')
elif isinstance(item,
Expand Down Expand Up @@ -196,6 +201,7 @@ def test_code():
'y': np.int64(66)
},
},
't': None,
'z': 'Hello world!',
'tuple_data': (np.int64(1), np.int64(2), np.int64(3)),
'list_data': [1.1, 2.2, 3.3],
Expand Down

0 comments on commit 8680526

Please sign in to comment.