Skip to content

ruff: Enable NPY (NumPy-specific) rules #2779

Closed

Description

@seisman

Currently, ruff provides three NumPy-specific rules (https://docs.astral.sh/ruff/rules/#numpy-specific-rules-npy), which can help us avoid deprecated NumPy functions.

To enable NumPy-specific rules, we just need to add NPY to the select option below:

pygmt/pyproject.toml

Lines 91 to 97 in 8f1d476

select = [
"E", # pycodestyle
"F", # pyflakes
"I", # isort
"UP", # pyupgrade
"W", # pycodestyle warnings
]

After enabling the NPY rules, running make format gives many [NPY002]*https://docs.astral.sh/ruff/rules/numpy-legacy-random/) warnings, like:

examples/gallery/histograms/histogram.py:15:1: NPY002 Replace legacy `np.random.seed` call with `np.random.Generator`
   |
13 | import pygmt
14 |
15 | np.random.seed(100)
   | ^^^^^^^^^^^^^^ NPY002
16 |
17 | # Generate random elevation data from a normal distribution
   |

The usage of np.random.seed(100) is deprecated. We should use something like below instead:

rng = np.random.default_rng(100)
rng.random()

Activity

  1. added
    maintenanceBoring but important stuff for the core devs
    help wantedHelping hands are appreciated
    on Oct 30, 2023
  2. yvonnefroehlich commented on Oct 30, 2023

    @yvonnefroehlich
    Member
  3. added this to the 0.11.0 milestone on Oct 31, 2023
  4. reopened this on Nov 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    maintenanceBoring but important stuff for the core devs

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions