Coverage for /home/ubuntu/Documents/Research/mut_p6/sacred/sacred/serializer.py: 94%

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

18 statements  

1import jsonpickle 

2import json as _json 

3from sacred import optional as opt 

4 

5json = jsonpickle 

6 

7 

8__all__ = ("flatten", "restore") 

9 

10 

11if opt.has_numpy: 

12 import jsonpickle.ext.numpy as jsonpickle_numpy 

13 

14 np = opt.np 

15 

16 jsonpickle_numpy.register_handlers() 

17 

18if opt.has_pandas: 

19 import jsonpickle.ext.pandas as jsonpickle_pandas 

20 

21 jsonpickle_pandas.register_handlers() 

22 

23 

24jsonpickle.set_encoder_options("simplejson", sort_keys=True, indent=4) 

25jsonpickle.set_encoder_options("demjson", compactly=False) 

26 

27 

28def flatten(obj): 

29 return _json.loads(json.encode(obj, keys=True)) 

30 

31 

32def restore(flat): 

33 return json.decode(_json.dumps(flat), keys=True)