Skip to content

Conversation

@yvonnefroehlich
Copy link
Member

Description of proposed changes

This PR aims to update the tests to follow ruff's NumPy rules, especially it addresses the NPY002 warning (please see https://docs.astral.sh/ruff/rules/numpy-legacy-random/):

NPY002 Replace legacy `np.random.seed` call with `np.random.Generator`

Example:

import numpy as np
np.random.seed(42)
np.random.normal()

is replaced by

rng = np.random.default_rng(seed=42)
rng.normal()

Affected tests

  • test_io.py
  • test_x2sys_cross (two times)

Please not the generated random numbers are not identical.

Related to the PRs

Fixes #2779 partly

Reminders

  • Run make format and make check to make sure the code follows the style guide.
  • Add tests for new features or tests that would have caught the bug that you're fixing.
  • Add new public functions/methods/classes to doc/api/index.rst.
  • Write detailed docstrings for all functions/methods.
  • If wrapping a new module, open a 'Wrap new GMT module' issue and submit reasonably-sized PRs.
  • If adding new functionality, add an example to docstrings or tutorials.
  • Use underscores (not hyphens) in names of Python files and directories.

Slash Commands

You can write slash commands (/command) in the first line of a comment to perform
specific operations. Supported slash commands are:

  • /format: automatically format and lint the code
  • /test-gmt-dev: run full tests on the latest GMT development version


assert isinstance(output, pd.DataFrame)
assert output.shape == (30, 12)
assert output.shape == (26, 12)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes make sense to me, but ping the original author @weiji14 to review.

@seisman seisman added maintenance Boring but important stuff for the core devs skip-changelog Skip adding Pull Request to changelog needs review This PR has higher priority and needs review. and removed documentation Improvements or additions to documentation labels Oct 31, 2023
@seisman
Copy link
Member

seisman commented Nov 2, 2023

Ping @weiji14

Copy link
Member

@weiji14 weiji14 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be ok 🙂

@seisman seisman removed the needs review This PR has higher priority and needs review. label Nov 2, 2023
@seisman seisman merged commit 728c916 into main Nov 2, 2023
@seisman seisman deleted the update-tests-NPY002 branch November 2, 2023 04:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintenance Boring but important stuff for the core devs skip-changelog Skip adding Pull Request to changelog

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ruff: Enable NPY (NumPy-specific) rules

4 participants