Skip to content

Commit

Permalink
fix: support NumPy <2 again
Browse files Browse the repository at this point in the history
Signed-off-by: Henry Schreiner <[email protected]>
  • Loading branch information
henryiii committed Aug 9, 2024
1 parent 8ec2788 commit ce5c0fd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/boost_histogram/_internal/hist.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,11 @@ def view(
def __array__(
self, dtype: np.typing.DTypeLike | None = None, *, copy: bool | None = None

Check warning on line 358 in src/boost_histogram/_internal/hist.py

View workflow job for this annotation

GitHub Actions / PyLint

W0621

Redefining name 'copy' from outer scope (line 4)
) -> 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
Expand Down
6 changes: 5 additions & 1 deletion tests/test_pandaslike.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down

0 comments on commit ce5c0fd

Please sign in to comment.