Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generated idata fails to be deserialized #421

Closed
carrascomj opened this issue Mar 3, 2023 · 2 comments
Closed

Generated idata fails to be deserialized #421

carrascomj opened this issue Mar 3, 2023 · 2 comments

Comments

@carrascomj
Copy link
Member

I have two idata.json outputs generated by maud sample (maud-metabolic-models==0.4.0.2) and none of them can be read back to memory.

Traceback:

>>> idata = az.from_json("idata.json")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/jorge/.virtualenvs/maud/lib/python3.9/site-packages/arviz/data/io_json.py", line 29, in from_json
    idata_dict = json.load(file)
ujson.JSONDecodeError: Unexpected character found when decoding 'Infinity'

Without ujson (using the stdlib json module), it also fails but with a more cryptic error.

@carrascomj
Copy link
Member Author

As a workaround

from glob import glob
from maud.loading_maud_inputs import load_maud_input
from maud.getting_idatas import get_idata

mi = load_maud_input("user_input")
idata = get_idata(glob("samples/*csv"), mi, "train")

works fine.

@teddygroves
Copy link
Member

I think this might be the cause of the problem: ultrajson/ultrajson#562.

The ujson library relatively recently changed how it encodes infinity from 'Inf' to 'Infinity'. When it tries to read a file with the old 'Inf's it raises the JSONDecodeError above.

I had a look in the idata.json file and it had 'Inf's (i.e. not 'Infinity's) in it, so I suspect the ujson reading the file might be incompatible with the one that made it.

I tried (with ujson 5.7.0 and arviz 0.14.0) doing the following and it worked ok:

import arviz as az
import numpy as np

t = az.from_dict({"bla": np.inf})
t.to_json("t.json")
t_loaded = az.from_json("t.json")

and this a) didn't raise an error and b) produced a file containing 'Infinity'.

I think we should maybe require a recent version of ujson in Maud in order to stop this issue coming up again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants