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

scatter plotting tests fail for recent matplotlib version #281

Closed
jkikstra opened this issue Oct 31, 2019 · 5 comments · Fixed by #380
Closed

scatter plotting tests fail for recent matplotlib version #281

jkikstra opened this issue Oct 31, 2019 · 5 comments · Fixed by #380
Labels

Comments

@jkikstra
Copy link
Collaborator

jkikstra commented Oct 31, 2019

With matplotlib version 3.1.1 installed, some pyam plotting tests fail.
More specifically, test_scatter, test_scatter_variables_with_meta_color, test_scatter_with_lines, and test_scatter_meta fail, because of IndexError: list index our of range, pyam\plotting.py:605
when:

pyam\core.py:1293: in scatter
    ax = plotting.scatter(df.dropna(), x, y, **kwargs)
pyam\plotting.py:605: in scatter
    handles = [handles[i] for i in idxs]

With matplotlib version 3.0.2 all of the aforementioned tests pass.

@jkikstra jkikstra changed the title scatter plotting tests fail for new matplotlib scatter plotting tests fail for recent matplotlib version Oct 31, 2019
gidden pushed a commit that referenced this issue Oct 31, 2019
* Update to build docs locally

* Update install.rst

* fix printing requirements in `install.rst`

* add space (as suggested by @znicholls)

* set `matplotlib` requirement as a quickfix for #281
@khaeru
Copy link
Contributor

khaeru commented Nov 1, 2019

The "quickfix" for this in 7d6b7ef / #280 broke message_ix builds.

The last build for iiasa/message_ix#249, Travis build #1167, succeeded; but build #1180 failed just now on OS X with the following error caused by pyam:

___________________ ERROR collecting tests/test_reporting.py ___________________
ImportError while importing test module '/Users/travis/build/iiasa/message_ix/tests/test_reporting.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
tests/test_reporting.py:15: in <module>
    import pyam
../../../miniconda/envs/testing/lib/python3.7/site-packages/pyam/__init__.py:1: in <module>
    from pyam.core import *
../../../miniconda/envs/testing/lib/python3.7/site-packages/pyam/core.py:16: in <module>
    from pyam import plotting
../../../miniconda/envs/testing/lib/python3.7/site-packages/pyam/plotting.py:4: in <module>
    import matplotlib.pyplot as plt
../../../miniconda/envs/testing/lib/python3.7/site-packages/matplotlib/pyplot.py:2374: in <module>
    switch_backend(rcParams["backend"])
../../../miniconda/envs/testing/lib/python3.7/site-packages/matplotlib/pyplot.py:207: in switch_backend
    backend_mod = importlib.import_module(backend_name)
../../../miniconda/envs/testing/lib/python3.7/importlib/__init__.py:127: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
../../../miniconda/envs/testing/lib/python3.7/site-packages/matplotlib/backends/backend_macosx.py:14: in <module>
    from matplotlib.backends import _macosx

E   ImportError: Python is not installed as a framework. The Mac OS X backend will not be able to function correctly if Python is not installed as a framework. See the Python documentation for more information on installing Python as a framework on Mac OS X. Please either reinstall Python as a framework, or try one of the other backends. If you are using (Ana)Conda please install python.app and replace the use of 'python' with 'pythonw'. See 'Working with Matplotlib on OSX' in the Matplotlib FAQ for more information.

Looking at the build log, this failure happens with matplotlib 3.0.2; the previous, successful build was using matplotlib 3.1.1. #280 was merged in between these two builds.

I will add a workaround to message_ix by forcing matplotlib to again update to the latest after pyam downgrades it.

IMHO, the actual fix should be to adjust pyam to work properly with the latest matplotlib; not to force any other software using pyam to run an outdated matplotlib.

@khaeru
Copy link
Contributor

khaeru commented Nov 1, 2019

A few more thoughts about the failure mode here:

  1. The message:

    Python is not installed as a framework. The Mac OS X backend will not be able to function correctly if Python is not installed as a framework. See the Python documentation for more information on installing Python as a framework on Mac OS X. Please either reinstall Python as a framework, or try one of the other backends. If you are using (Ana)Conda please install python.app and replace the use of 'python' with 'pythonw'. See 'Working with Matplotlib on OSX' in the Matplotlib FAQ for more information.

    …mentions the conda package python.app.

  2. python.app is not mentioned as a conda dependency of pyam.

  3. However, inspecting the pyam build logs (e.g. of release candidate 0.3.0 #282) shows that it does get installed on Travis/macOS.

  4. Thus, it must be a conda dependency of some conda dependency of pyam.

  5. Because message_ix is currently working around Bug fix release #259 (or hotfix for pandas 0.25.0 update, closes #245 #246 I guess), pyam is not installed via conda, but from source.

  6. Thus the setup.py dependencies of pyam are installed from PyPI—not the conda dependencies…

  7. …and so python.app does not get installed (in contrast to point 3), and eventually the build fails.

When the next release comes out, the workaround in point 5 will get reverted, so point 6/7 cease to happen, python.app will likely get pulled in for message_ix builds, and they may pass even with matplotlib 3.0.2. However, the suggested fix in my previous comment would still be preferred.

khaeru added a commit to iiasa/message_ix that referenced this issue Nov 1, 2019
Main changes:

- Add message_ix.models module
- Adjust tools.add_year for ixmp API changes
- Add Scenario._backend, .years_active; delete .remove_solution
- Delete Scenario.clone
- Use Backend.ms_cat_set_elements
- Use Backend.ms_* methods; remove Scenario._jobj shim
- Re-add thin Scenario.clone() wrapper
- Adjust docs cross-reference to ixmp
- Convert Path to str in message_ix.cli
- Provide firstmodelyear using Scenario.cat
- Update RELEASE_NOTES
- Coerce to int in Scenario.firstmodelyear
- Remove Scenario._backend (now handled by ixmp)
- Adjust add_par signature in testing.make_westeros
- Compute years_active in Scenario, rather than using backend
- Update documentation; remove parallel copy of ixmp API docs
- Move CPLEX optfile code to MESSAGE class; adjust docs
- Fix small docs typos
- Further docs improvements; remove _init_scenario (no-op)
- Proofread docs and comments
- Update API docs per @gidden reivew
- Further improve API docs

Tidy CI files per ixmp:

- Fix pip VCS URLs
- Update Travis caching and env.sh
- Update ci/requirements.txt
- Add ci/appveyor-install.ps1 to echo ixmp
- On AppVeyor, update pip using conda
- On Travis, update pip using conda
- Add numpy to explicit requirements
- Add conda info to Travis for debugging
- Travis: install dependencies using conda
- Split requirements.txt
- Give conda --yes
- Add pip to testing conda env
- Install conda-requirements into testing conda env
- Install pip-requirements into testing conda environment
- Update doc/requirements.txt
- Add to conda-requirements
- Move JPype, pint, plotnine from conda-req to pip-req
- Return JPype to conda-req as JPype1
- Append conda-forge to default channels for JPype
- Adjust coveragerc
- Return CI to ixmp@master
- Work around IAMconsortium/pyam#280 / IAMconsortium/pyam#281
@awais307
Copy link

The pyam requirement for an outdated (3.0.2) version of matplotlib is causing difficulties on my system, where another code requires the latest matplotlib. So I am forced to have two conda environments; one for any code using pyam and other one requiring latest matplotlib version.

@znicholls
Copy link
Collaborator

A possible quickfix for the build failures discussed by @khaeru could be to tell matplotlib to use a different backend (e.g. https://github.com/znicholls/silicone/blob/2e64d8a8a20b00ec545b280e7e3253feaa51761e/.github/workflows/test-pypi-install.yml#L23)

@znicholls
Copy link
Collaborator

IMHO, the actual fix should be to adjust pyam to work properly with the latest matplotlib; not to force any other software using pyam to run an outdated matplotlib.

Although I fully agree with this (but acknowledge that anything to do with plotting and plotting tests is super hard).

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

Successfully merging a pull request may close this issue.

5 participants