diff --git a/src/boost_histogram/_internal/hist.py b/src/boost_histogram/_internal/hist.py index da63ea7e..9bb9a3e4 100644 --- a/src/boost_histogram/_internal/hist.py +++ b/src/boost_histogram/_internal/hist.py @@ -357,7 +357,11 @@ def view( def __array__( self, dtype: np.typing.DTypeLike | None = None, *, copy: bool | None = None ) -> np.typing.NDArray[Any]: - return np.asarray(self.view(False), dtype=dtype, copy=copy) # type: ignore[no-any-return,call-overload] + # The copy kw is new in NumPy 2.0 + kwargs = {} + if copy is not None: + kwargs["copy"] = copy + return np.asarray(self.view(False), dtype=dtype, **kwargs) # type: ignore[no-any-return, call-overload] def __eq__(self, other: Any) -> bool: return hasattr(other, "_hist") and self._hist == other._hist diff --git a/tests/test_pandaslike.py b/tests/test_pandaslike.py index ae58a490..15e78c52 100644 --- a/tests/test_pandaslike.py +++ b/tests/test_pandaslike.py @@ -12,7 +12,11 @@ def __init__(self, array): self.array = np.asarray(array) def __array__(self, dtype=None, *, copy=None): - return np.asarray(self.array, dtype=dtype, copy=copy) + # Copy is new in NumPy 2.0 + kw = {} + if copy is not None: + kw["copy"] = copy + return np.asarray(self.array, dtype=dtype, **kw) def test_setting_weighted_profile_convertable():