Netflix/sureal

Python2.7, --print / --output-dir causes "float64 not serializable" error.

x2eliah opened this issue · 1 comments

Using python 2.7 in a clean virtual environment, using --print and/or --output-dir arguments causes a serialization error.

Environment setup:

git clone sureal
virtualenv srEnv
source srEnv/bin/activate
cd sureal
cp sureal/test/resource/NFLX_dataset_public_raw_PARTIAL.py ../NFLX_dataset_public_PARTIAL.py
pip install -r requirements.txt
pip install .

python -m sureal MOS ../NFLX_dataset_public_raw_PARTIAL.py --print

produces:

[crop]$ python -m sureal MOS ../NFLX_dataset_public_raw_PARTIAL.py --print
Run model MosModel on dataset NFLX_dataset_public_raw_PARTIAL.py
Dataset: ../NFLX_dataset_public_raw_PARTIAL.py
Subjective Model: MOS 1.0
Result:
Traceback (most recent call last):
  File "/usr/lib/python2.7/runpy.py", line 174, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/home/elijs/QoEAT_Sureal/sureal/sureal/__main__.py", line 77, in <module>
    ret = main()
  File "/home/elijs/QoEAT_Sureal/sureal/sureal/__main__.py", line 65, in main
    json.dumps(results[0], indent=4, sort_keys=True)
  File "/usr/lib/python2.7/json/__init__.py", line 251, in dumps
    sort_keys=sort_keys, **kw).encode(obj)
  File "/usr/lib/python2.7/json/encoder.py", line 209, in encode
    chunks = list(chunks)
  File "/usr/lib/python2.7/json/encoder.py", line 434, in _iterencode
    for chunk in _iterencode_dict(o, _current_indent_level):
  File "/usr/lib/python2.7/json/encoder.py", line 408, in _iterencode_dict
    for chunk in chunks:
  File "/usr/lib/python2.7/json/encoder.py", line 442, in _iterencode
    o = _default(o)
  File "/usr/lib/python2.7/json/encoder.py", line 184, in default
    raise TypeError(repr(o) + " is not JSON serializable")
TypeError: 0     4.884615
1     4.692308
2     4.730769
3     4.884615
4     4.461538
5     4.730769
6     4.730769
7     2.115385
8     1.961538
9     2.653846
10    2.807692
11    3.576923
12    4.423077
13    4.884615
14    4.846154
15    1.000000
16    1.923077
17    2.769231
18    3.269231
19    3.961538
20    4.346154
21    4.500000
22    1.192308
23    1.576923
24    3.153846
25    3.461538
26    4.153846
27    4.615385
28    4.692308
29    1.307692
30    2.615385
31    2.923077
32    3.192308
33    3.653846
34    4.000000
35    4.384615
36    4.653846
37    4.769231
38    1.115385
39    1.846154
40    2.461538
41    3.076923
42    4.230769
43    4.384615
44    4.769231
45    1.576923
46    2.576923
47    3.230769
48    3.307692
49    4.230769
50    4.538462
dtype: float64 is not JSON serializable

This seems to occur regardless of model.

slhck commented

Should be fixed in the PR. This printing method is not very useful anyway since the output is not machine-readable (due to it being interspersed with other results). There may be other places where this is necessary.