Skip to content

NPY201 rules seem to miss imports for NAN #12195

@xmatthias

Description

@xmatthias

Using the following test file should show multiple deprecation warnings - but only shows one while using ruff 0.5.0 (the latest afaik).

from numpy import nan, NaN, NAN

import numpy as np

np.NaN
np.NAN
np.nan

ruff check test_npy.py --preview --select NPY2

test_npy.py:5:1: NPY201 [*] `np.NaN` will be removed in NumPy 2.0. Use `numpy.nan` instead.
  |
3 | import numpy as np
4 | 
5 | np.NaN
  | ^^^^^^ NPY201
6 | np.NAN
7 | np.nan
  |
  = help: Replace with `numpy.nan`

Found 1 error.
[*] 1 fixable with the `--fix` option

In reality, np.NAN is also not valid, so should raise an error, too.

Also, explicit imports (not used through np.xxx) seem to be completely ignored ...
Neither is from numpy import NaN, NAN (only from numpy import nan is still valid for numpy2.0).

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issueGood for newcomershelp wantedContributions especially welcomeruleImplementing or modifying a lint rule

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions