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

matplotlib 3.5.0rc1 raises AttributeError in test_no_numpy_warnings #12431

Closed
Tracked by #12430
dhomeier opened this issue Nov 6, 2021 · 2 comments · Fixed by #12437
Closed
Tracked by #12430

matplotlib 3.5.0rc1 raises AttributeError in test_no_numpy_warnings #12431

dhomeier opened this issue Nov 6, 2021 · 2 comments · Fixed by #12437

Comments

@dhomeier
Copy link
Contributor

dhomeier commented Nov 6, 2021

Description

Uncaught exception in visualization.wcsaxes test because matplotlib 3.5.0rc does not identify as MATPLOTLIB_DEV.

Expected behavior

Intercept exception as required by mpl version.

Actual behavior

Failure in

_________________________________________________________________________ test_no_numpy_warnings[contours] _________________________________________________________________________
ignore_matplotlibrc = None, tmpdir = local('/private/var/folders/bb/f_z2vsjd21d_p0jpqxzhhwhh00027w/T/pytest-of-derek/pytest-87/test_no_numpy_warnings_contour0')
grid_type = 'contours'

    @pytest.mark.parametrize('grid_type', ['lines', 'contours'])
    def test_no_numpy_warnings(ignore_matplotlibrc, tmpdir, grid_type):
        ax = plt.subplot(1, 1, 1, projection=WCS(TARGET_HEADER))
        ax.imshow(np.zeros((100, 200)))
        ax.coords.grid(color='white', grid_type=grid_type)
    
        if MATPLOTLIB_DEV and grid_type == 'contours':
            ctx = pytest.raises(AttributeError, match='dpi')
        else:
            ctx = nullcontext()
    
        with pytest.warns(None) as warning_lines, ctx:
>           plt.savefig(tmpdir.join('test.png').strpath)

/opt/lib/python3.10/site-packages/astropy/visualization/wcsaxes/tests/test_misc.py:90: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
/opt/lib/python3.10/site-packages/matplotlib/pyplot.py:959: in savefig
    fig.canvas.draw_idle()   # need this if 'transparent=True' to reset colors
/opt/lib/python3.10/site-packages/matplotlib/backend_bases.py:2050: in draw_idle
    self.draw(*args, **kwargs)
/opt/lib/python3.10/site-packages/matplotlib/backends/backend_agg.py:434: in draw
    self.figure.draw(self.renderer)
/opt/lib/python3.10/site-packages/matplotlib/artist.py:73: in draw_wrapper
    result = draw(artist, renderer, *args, **kwargs)
/opt/lib/python3.10/site-packages/matplotlib/artist.py:50: in draw_wrapper
    return draw(artist, renderer)
/opt/lib/python3.10/site-packages/matplotlib/figure.py:2803: in draw
    mimage._draw_list_compositing_images(
/opt/lib/python3.10/site-packages/matplotlib/image.py:132: in _draw_list_compositing_images
    a.draw(renderer)
/opt/lib/python3.10/site-packages/astropy/visualization/wcsaxes/core.py:456: in draw
    super().draw(renderer, **kwargs)
/opt/lib/python3.10/site-packages/matplotlib/artist.py:50: in draw_wrapper
    return draw(artist, renderer)
/opt/lib/python3.10/site-packages/matplotlib/axes/_base.py:3082: in draw
    mimage._draw_list_compositing_images(
/opt/lib/python3.10/site-packages/matplotlib/image.py:132: in _draw_list_compositing_images
    a.draw(renderer)
/opt/lib/python3.10/site-packages/matplotlib/artist.py:50: in draw_wrapper
    return draw(artist, renderer)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <matplotlib.collections.PathCollection object at 0x120ff9de0>, renderer = <matplotlib.backends.backend_agg.RendererAgg object at 0x120b68cd0>

    @artist.allow_rasterization
    def draw(self, renderer):
>       self.set_sizes(self._sizes, self.figure.dpi)
E       AttributeError: 'NoneType' object has no attribute 'dpi'

/opt/lib/python3.10/site-packages/matplotlib/collections.py:976: AttributeError
================================================================================= warnings summary =================================================================================
../../opt/lib/python3.10/site-packages/_pytest/cacheprovider.py:428
  /opt/lib/python3.10/site-packages/_pytest/cacheprovider.py:428: PytestCacheWarning: could not create cache path /opt/lib/python3.10/site-packages/astropy/visualization/wcsaxes/.pytest_cache/v/cache/nodeids
    config.cache.set("cache/nodeids", sorted(self.cached_nodeids))

../../opt/lib/python3.10/site-packages/_pytest/cacheprovider.py:382
  /opt/lib/python3.10/site-packages/_pytest/cacheprovider.py:382: PytestCacheWarning: could not create cache path /opt/lib/python3.10/site-packages/astropy/visualization/wcsaxes/.pytest_cache/v/cache/lastfailed
    config.cache.set("cache/lastfailed", self.lastfailed)

../../opt/lib/python3.10/site-packages/_pytest/stepwise.py:49
  /opt/lib/python3.10/site-packages/_pytest/stepwise.py:49: PytestCacheWarning: could not create cache path /opt/lib/python3.10/site-packages/astropy/visualization/wcsaxes/.pytest_cache/v/cache/stepwise
    session.config.cache.set(STEPWISE_CACHE_DIR, [])

-- Docs: https://docs.pytest.org/en/stable/warnings.html
============================================================================= short test summary info ==============================================================================
FAILED ../../opt/lib/python3.10/site-packages/astropy/visualization/wcsaxes/tests/test_misc.py::test_no_numpy_warnings[contours] - AttributeError: 'NoneType' object has no attri...
============================================================== 1 failed, 184 passed, 45 skipped, 3 warnings in 10.72s ==============================================================

Steps to Reproduce

With astropy 5.0rc1, matplotlib 3.5.0rc1

>>> import astropy
>>> import matplotlib
>>> from packaging.version import Version
>>> Version(matplotlib.__version__)
<Version('3.5.0rc1')>
>>> Version(matplotlib.__version__).is_devrelease
False
>>> astropy.test(package='visualization.wcsaxes')

System Details

[same for Python 3.9.6, 3.9.8]
Running tests with Astropy version 5.0rc1.
Running tests in /opt/lib/python3.10/site-packages/astropy/visualization/wcsaxes.
Platform: macOS-10.14.6-x86_64-i386-64bit
Executable: /opt/bin/python3.10
Full Python Version:
3.10.0 (default, Oct 5 2021, 03:51:16) [Clang 11.0.0 (clang-1100.0.33.17)]

encodings: sys: utf-8, locale: UTF-8, filesystem: utf-8
byteorder: little
float info: dig: 15, mant_dig: 15

Package versions:
Numpy: 1.21.2
Scipy: 1.7.1
Matplotlib: 3.5.0rc1
h5py: 3.5.0
Pandas: 1.3.3
PyERFA: 2.0.0
Cython: 0.29.24
Scikit-image: not available
asdf: 2.8.1

@astrofrog
Copy link
Member

I think we should fix the underlying issue here which is that savefig should not be erroring in the first place with any version.

@astrofrog
Copy link
Member

I've managed to narrow it down to the code in this issue: matplotlib/matplotlib#21569 - this is related to a change in contours from LineCollection to PathCollection, and the fact the contour lines aren't removed correctly.

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

Successfully merging a pull request may close this issue.

2 participants