Netflix/sureal

Python3, map object is not subscriptable + empty figs 2 [,3,4].

x2eliah opened this issue · 5 comments

Current master seems not working in python3.6.7 (clean virtual environment with installed requirements.txt). Checked with NFLX reduced dataset pyfile taken from test directory.

All models fail to work (first figure normal, second etc. figures are generated but empty).

reproduction steps:

git clone [sureal's dl link]

python3 -m venv srEnv
cp sureal/test/resource/NFLX_dataset_public_raw_PARTIAL.py data.py
source srEnv/bin/activate
cd sureal
pip install -r requirements.txt
pip install .

python3 -m sureal MLE ../data.py --print

produces:

Run model MaximumLikelihoodEstimationModel on dataset data.py
No handles with labels found to put in legend.
No handles with labels found to put in legend.
Dataset: ../data.py
Traceback (most recent call last):
  File "/usr/lib/python3.6/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib/python3.6/runpy.py", line 85, in _run_code
    exec(code, 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 63, in main
    print(("Subjective Model: {} {}".format(subjective_models[0].TYPE, subjective_models[0].VERSION)))
TypeError: 'map' object is not subscriptable

Seems to happen with all models. Without the --print command, same effective outcome (empty figures) without the error trace in terminal.

Notes:
in-environment python3:

Python 3.6.7 (default, Oct 22 2018, 11:32:17) 
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>

pip-freeze:

cycler==0.10.0
kiwisolver==1.0.1
matplotlib==3.0.2
numpy==1.15.4
pandas==0.23.4
pkg-resources==0.0.0
pyparsing==2.3.0
python-dateutil==2.7.5
pytz==2018.9
scipy==1.2.0
six==1.12.0
sureal==0.2
slhck commented

Hm, weird, everything seemed to run fine when I tested.

slhck commented

subjective_models should be a returned as a list, not a map (which is a generator). I thought this was converted already when moving from Python 2 to a Python 3 compatible syntax.
Not sure if I will have time to investigate this, but thanks for raising the issue!

slhck commented

I created a PR that fixes this. @li-zhi could you please have a look?

I am debating on the use of map vs list comprehension. Traditionally I prefer map since it can be easily converted into parallel map. In Python 3 apparently the return type of map has been changed to iterator for memory optimization reason:
https://stackoverflow.com/questions/1303347/getting-a-map-to-return-a-list-in-python-3-x

I guess it doesn't make much a difference for Sureal since we are dealing with very small problems.

I'll go ahead with the merge. Many thanks!

slhck commented

Thanks for the merge!

Yeah, map now returns a generator, which means that without a simple "hack" (wrapping it in a list constructor), you'd have to rewrite most of the code that works with the result of the map expression.

There's potential for memory optimization, but I didn't feel like going through the codebase to see where and how these variables were being used.