FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

[Bug]: NumPy 1.24 deprecation warnings · Issue #24865 · matplotlib/matplotlib · GitHub

Repository navigation

[Bug]: NumPy 1.24 deprecation warnings #24865

Closed

Description

Bug summary

Starting NumPy 1.24 I observe several deprecation warnings.

Code for reproduction

import matplotlib.pyplot as plt
import numpy as np

plt.get_cmap()(np.empty((0, ), dtype=np.uint8))

Actual outcome

/usr/lib/python3.10/site-packages/matplotlib/colors.py:730: DeprecationWarning: NumPy will stop allowing conversion of out-of-bound Python integers to integer arrays.  The conversion of 257 to uint8 will fail in the future.
For the old behavior, usually:
    np.array(value).astype(dtype)`
will give the desired result (the cast overflows).
  xa[xa > self.N - 1] = self._i_over
/usr/lib/python3.10/site-packages/matplotlib/colors.py:731: DeprecationWarning: NumPy will stop allowing conversion of out-of-bound Python integers to integer arrays.  The conversion of 256 to uint8 will fail in the future.
For the old behavior, usually:
    np.array(value).astype(dtype)`
will give the desired result (the cast overflows).
  xa[xa < 0] = self._i_under
/usr/lib/python3.10/site-packages/matplotlib/colors.py:732: DeprecationWarning: NumPy will stop allowing conversion of out-of-bound Python integers to integer arrays.  The conversion of 258 to uint8 will fail in the future.
For the old behavior, usually:
    np.array(value).astype(dtype)`
will give the desired result (the cast overflows).
  xa[mask_bad] = self._i_bad

Expected outcome

No warnings.

Additional information

No response

Operating system

ArchLinux

Matplotlib Version

3.6.2

Matplotlib Backend

QtAgg

Python version

Python 3.10.9

Jupyter version

No response

Installation

Linux package manager

Activity

  1. dstansby commented on Jan 1, 2023

    Member

    Thanks for the report! Unfortunately I can't reproduce this. What version of numpy are you using when the warning appears?

  2. sergiud commented on Jan 1, 2023

    Author

    Sorry, forgot to mention that you need to enable the warnings during normal execution, e.g., python -W always <file>.py. In my case, the warnings are issued during pytest run which seems to activate these warnings by default.

    As for the NumPy version, I'm running

    $ python -c 'import numpy; print(numpy.__version__)'
    1.24.0
  3. dstansby commented on Jan 1, 2023

    Member

    Thanks, I can now reproduce 😄

  4. added this to the v3.7.0 milestone on Jan 7, 2023
  5. oscargus commented on Jan 10, 2023

    Member

    The problem is that there are three more values, that are by default out of range in this case, to note specific cases:

    self._i_under = self.N
    self._i_over = self.N + 1
    self._i_bad = self.N + 2

    (N = 256 by default)

    These are then assigned to out-of-range and masked/bad values here:

    xa[xa > self.N - 1] = self._i_over
    xa[xa < 0] = self._i_under
    xa[mask_bad] = self._i_bad

    which now raises a deprecation warning.

    I think that one way forward would be to check the type of xa for int/uint and in that case take modulo the maximum value for self._i_over etc. This is basically what happens now anyway, but we need to do it explicitly rather than relying on numpy doing it. (I cannot really see how this makes sense from a color perspective, but we will at least keep the current behavior.)

  6. tacaswell commented on Jan 11, 2023

    Member

    I think this is exposing a real bug that we need to promote the input data to be bigger than uint8. What we are doing here is buildin a lookup up table, the first N entries are for for values into the actually color map and then the next 3 entries are the special cases for over/under/bad so xa needs to be big enough to hold self.N + 2 as values.

  7. added
    Release criticalFor bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions.
    on Jan 13, 2023
  8. QuLogic commented on Jan 13, 2023

    Member

    I don't know if this is a bigger bug or not, but I would like us to have fixed any deprecation warnings from dependencies before 3.7 is out (or if necessary a quick 3.7.1.)

  9. dangersniru commented on May 25, 2024

    Change it to (np.array()).astype(np.int8) helps.

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

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions


      Back | FazBrowse Home | New Git URL