Skip to content

PY_SSIZE_T_CLEAN warning with Python 3.9 and Matplotlib 3.0 #10954

Description

@dhomeier

Description

With matplotlib 3.0.x test_no_numpy_warnings runs into an unexpected deprecation warning.

Steps to Reproduce

astropy.test(package='visualization', args='-vk numpy_warn')
...
Running tests with Astropy version 4.2.dev1150+g3421137b6.d20201027.
Running tests in lib/python3.9/site-packages/astropy/visualization.

Date: 2020-10-27T13:58:40

Platform: macOS-10.14.6-x86_64-i386-64bit

Executable: /opt/bin/python3.9

Full Python Version: 
3.9.0 (default, Oct 10 2020, 10:27:03) 
[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.19.2
Scipy: 1.5.3
Matplotlib: 3.0.3
h5py: not available
Pandas: not available
PyERFA: 1.7.0
Cython: 0.29.21
Scikit-image: not available
asdf: 2.7.1

Using Astropy options: remote_data: any.

hypothesis profile 'default' -> database=DirectoryBasedExampleDatabase('/Users/derek/.hypothesis/examples')
rootdir: /Users/derek
plugins: arraydiff-0.3, xdist-2.1.0, astropy-header-0.1.2, hypothesis-5.16.0, cov-2.10.1, flaky-3.7.0, asdf-2.7.1, remotedata-0.3.2, mock-3.3.1, forked-1.3.0, openfiles-0.5.0, doctestplus-0.8.0, expect-1.1.0, flake8-1.0.6
collected 479 items / 477 deselected / 2 selected                                                                                                                                  

lib/python3.9/site-packages/astropy/visualization/wcsaxes/tests/test_misc.py::test_no_numpy_warnings[lines] FAILED                                                           [ 50%]
lib/python3.9/site-packages/astropy/visualization/wcsaxes/tests/test_misc.py::test_no_numpy_warnings[contours] FAILED                                                        [100%]

===================================================================================== FAILURES =====================================================================================
__________________________________________________________________________ test_no_numpy_warnings[lines] ___________________________________________________________________________

ignore_matplotlibrc = None, tmpdir = local('/private/var/folders/7l/j6rbh6fw8xjc4w0059bv63_h00027w/T/pytest-of-derek/pytest-18/test_no_numpy_warnings_lines_0'), grid_type = 'lines'

    @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)
    
        with pytest.warns(None) as warning_lines:
            plt.savefig(tmpdir.join('test.png').strpath)
    
        # There should be no warnings raised if some pixels are outside WCS
        # (since this is normal).
        # BUT catch_warning was ignoring some warnings before, so now we
        # have to catch it. Otherwise, the pytest filterwarnings=error
        # setting in setup.cfg will fail this test.
        # There are actually multiple warnings but they are all similar.
        for w in warning_lines:
            print(w.message)
            w_msg = str(w.message)
>           assert ('converting a masked element to nan' in w_msg or
                    'No contour levels were found within the data range' in w_msg or
                    'np.asscalar(a) is deprecated since NumPy v1.16' in w_msg)
E           assert ('converting a masked element to nan' in "PY_SSIZE_T_CLEAN will be required for '#' formats" or 'No contour levels were found within the data range' in "PY_SSIZE_T_CLEAN will be required for '#' formats" or 'np.asscalar(a) is deprecated since NumPy v1.16' in "PY_SSIZE_T_CLEAN will be required for '#' formats")

lib/python3.9/site-packages/astropy/visualization/wcsaxes/tests/test_misc.py:95: AssertionError
------------------------------------------------------------------------------- Captured stdout call -------------------------------------------------------------------------------
PY_SSIZE_T_CLEAN will be required for '#' formats
_________________________________________________________________________ test_no_numpy_warnings[contours] _________________________________________________________________________

...

This is related to https://bugs.python.org/issue36381 and seems fixed as of Matplotlib 3.1.
Adding it to the list of expected warnings would be trivial, but if the minimum version is increased to >= 3.1.0 as per #10900 (comment) there will probably be no further action needed.

Activity

  1. pllim commented on Oct 27, 2020

    @pllim
    Member

    Hmm... We can choose to:

  2. dhomeier commented on Oct 27, 2020

    @dhomeier
    ContributorAuthor

    or

    • [conditionally for matplotlib < 3.1?] add "PY_SSIZE_T_CLEAN will be required for '#' formats" in w_msg to the list.
  3. bsipocz commented on Oct 27, 2020

    @bsipocz
    Member

    3.1 is a year and a bit old, feels a bit too recent, but if everyone agrees it can certainly be a bump for 4.2

  4. added
    zzz 💤 Python3.10archived: Python 3.10 is no longer supported
    zzz 💤 Python3.9archived: Python 3.9 is no longer supported
    and removed
    zzz 💤 Python4archived: Python 4 hopefully not happening
    on Oct 27, 2020
  5. pllim commented on Oct 27, 2020

    @pllim
    Member

    How about #10956?

  6. dhomeier commented on Oct 28, 2020

    @dhomeier
    ContributorAuthor

    Closed by #10956

  7. pllim commented on Nov 9, 2020

    @pllim
    Member

    Seeing a notification about this now reminded me of

    ignore:PY_SSIZE_T_CLEAN will be required for '#' formats

  8. dhomeier commented on Nov 9, 2020

    @dhomeier
    ContributorAuthor

    Doh, just got the same warning & test failure with Python 3.8.6.
    Although https://bugs.python.org/issue36381 mentioned a PendingDeprecationWarning for the 3.8 branch, this was apparently changed later to DeprecationWarning in python/cpython#12473 (if it even makes a difference).
    Anyway obviously need to extend the fix to sys.version_info >= (3, 8)...

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions