fix: Obs.dump can now be provided with a description for the json.gz

file
This commit is contained in:
Fabian Joswig 2022-02-13 16:21:27 +00:00
parent 698d1a7d57
commit e80fde6630

View file

@ -597,7 +597,7 @@ class Obs:
return dict(zip(self.e_names, sizes)) return dict(zip(self.e_names, sizes))
def dump(self, filename, datatype="json.gz", **kwargs): def dump(self, filename, datatype="json.gz", description="", **kwargs):
"""Dump the Obs to a file 'name' of chosen format. """Dump the Obs to a file 'name' of chosen format.
Parameters Parameters
@ -607,6 +607,8 @@ class Obs:
datatype : str datatype : str
Format of the exported file. Supported formats include Format of the exported file. Supported formats include
"json.gz" and "pickle" "json.gz" and "pickle"
description : str
Description for output file, only relevant for json.gz format.
path : str path : str
specifies a custom path for the file (default '.') specifies a custom path for the file (default '.')
""" """
@ -617,7 +619,7 @@ class Obs:
if datatype == "json.gz": if datatype == "json.gz":
from .input.json import dump_to_json from .input.json import dump_to_json
dump_to_json([self], file_name) dump_to_json([self], file_name, description=description)
elif datatype == "pickle": elif datatype == "pickle":
with open(file_name + '.p', 'wb') as fb: with open(file_name + '.p', 'wb') as fb:
pickle.dump(self, fb) pickle.dump(self, fb)