Skip to content

Commit

Permalink
Added unpicklable keyword to .json()
Browse files Browse the repository at this point in the history
  • Loading branch information
rgerkin committed Jun 1, 2021
1 parent 4454dca commit 9e66e5e
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions sciunit/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ def properties(self) -> dict:
return self._properties()

def json(
self, add_props: bool = False, string: bool = True, simplify: bool = True
self, add_props: bool = False, string: bool = True, unpicklable=False, simplify: bool = True
) -> str:
"""Generate a Json format encoded sciunit instance.
Expand All @@ -371,6 +371,7 @@ def json(
keys (list, optional): Only the keys in `keys` will be included in the json content. Defaults to None.
exclude (list, optional): The keys in `exclude` will be excluded from the json content. Defaults to None.
string (bool, optional): The json content will be `str` type if True, `dict` type otherwise. Defaults to True.
unpicklable (bool, optional): Whether to make certain components unpicklable or not. Default to False.
indent (None, optional): If indent is a non-negative integer or string, then JSON array elements and object members
will be pretty-printed with that indent level. An indent level of 0, negative, or "" will only
insert newlines. None (the default) selects the most compact representation. Using a positive integer
Expand All @@ -389,7 +390,7 @@ def json(
jsonpickle.handlers.register(pq.Quantity, handler=QuantitiesHandler)
jsonpickle.handlers.register(pq.UnitQuantity, handler=UnitQuantitiesHandler)

str_result = jsonpickle.encode(self, make_refs=False, unpicklable=False)
str_result = jsonpickle.encode(self, make_refs=False, unpicklable=unpicklable)
result = json.loads(str_result)

def do_simplify(d):
Expand Down Expand Up @@ -569,4 +570,4 @@ def flatten(self, obj, data):
def restore(self, data):
units = data['py/unitquantity']
return pq.unit_registry[units]


0 comments on commit 9e66e5e

Please sign in to comment.