Skip to content

np.trapz is deprecated in NumPy 2.0+; use np.trapezoid #1

Description

@defnalk

Description

`coordination_number()` in `analysis/scripts/analyze_hydration.py:147` calls `np.trapz`, which was deprecated in NumPy 2.0 and emits a `DeprecationWarning` in 2.1+. NumPy intends to remove the alias in a future release, at which point this script will hard-fail with `AttributeError: module 'numpy' has no attribute 'trapz'`.

Reproduction

On any environment with NumPy ≥ 2.0:

```python
import numpy as np
np.trapz([0, 1, 4, 9], [0, 1, 2, 3])

DeprecationWarning: 'trapz' is deprecated. Use 'trapezoid' instead.

```

The SURF environment ships NumPy 2.x via the conda env file, so this will surface as soon as anyone runs the analysis.

Expected

Use `np.trapezoid` (available in NumPy ≥ 2.0). For backwards compatibility with NumPy 1.x environments, fall back via `getattr(np, 'trapezoid', np.trapz)`.

Location

`analysis/scripts/analyze_hydration.py:147`

Activity

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

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions