Skip to content

DeprecationWarning in numpy.clip() for numpy 2 #10103

@deltamarnix

Description

@deltamarnix

What happened?

When calling numpy.clip (not xarray.DataArray.clip), I receive a DeprecationWarning:

site-packages\numpy_core\fromnumeric.py:48: DeprecationWarning: array_wrap must accept context and return_scalar arguments (positionally) in the future. (Deprecated NumPy 2.0)

What did you expect to happen?

That the deprecation warning is fixed.

Minimal Complete Verifiable Example

import xarray as xr
import numpy as np
import warnings

warnings.filterwarnings("always")

da = xr.DataArray(
    np.random.rand(4, 3),
    dims=("x", "y"),
    coords={"x": [0, 1, 2, 3], "y": [0, 1, 2]},
)
clipped = np.clip(da, 0.3, 0.6)

MVCE confirmation

  • Minimal example — the example is as focused as reasonably possible to demonstrate the underlying issue in xarray.
  • Complete example — the example is self-contained, including all data and the text of any traceback.
  • Verifiable example — the example copy & pastes into an IPython prompt or Binder notebook, returning the result.
  • New issue — a search of GitHub Issues suggests this is not a duplicate.
  • Recent environment — the issue occurs with the latest version of xarray and its dependencies.

Relevant log output

site-packages\numpy\_core\fromnumeric.py:48: DeprecationWarning: __array_wrap__ must accept context and return_scalar arguments (positionally) in the future. (Deprecated NumPy 2.0)

Anything else we need to know?

No response

Environment

  • python = "==3.12.9"
  • xarray = "==2025.1.2"
  • numpy = "==2.1.3"

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugtopic-arraysrelated to flexible array support

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions