Skip to content

Commit

Permalink
Fix json nan-serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
thorbjoernl committed Jul 30, 2024
1 parent d0ab8c0 commit e8d9689
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/aerovaldb/jsondb/jsonfiledb.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ def json_dumps_wrapper(obj, **kwargs) -> str:
"""
Wrapper which calls simplejson.dumps with the correct options, known to work for objects
returned by Pyaerocom.
This ensures that nan values are serialized as null to be compliant with the json standard.
"""
return simplejson.dumps(obj, allow_nan=True, **kwargs)
return simplejson.dumps(obj, ignore_nan=True, **kwargs)


class AerovalJsonFileDB(AerovalDB):
Expand Down
2 changes: 1 addition & 1 deletion tests/jsondb/test_jsonfiledb.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ def test_write_and_read_of_nan(tmp_path):

read = db.get_by_uri("./test")

assert math.isnan(read["value"])
assert read["value"] is None


def test_exception_on_unexpected_args():
Expand Down

0 comments on commit e8d9689

Please sign in to comment.