Coverage for sacred/sacred/serializer.py: 100%
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1import jsonpickle
2import json as _json
3from sacred import optional as opt
5json = jsonpickle
8__all__ = ("flatten", "restore")
11if opt.has_numpy:
12 import jsonpickle.ext.numpy as jsonpickle_numpy
14 np = opt.np
16 jsonpickle_numpy.register_handlers()
18if opt.has_pandas:
19 import jsonpickle.ext.pandas as jsonpickle_pandas
21 jsonpickle_pandas.register_handlers()
24jsonpickle.set_encoder_options("simplejson", sort_keys=True, indent=4)
25jsonpickle.set_encoder_options("demjson", compactly=False)
28def flatten(obj):
29 return _json.loads(json.encode(obj, keys=True))
32def restore(flat):
33 return json.decode(_json.dumps(flat), keys=True)