Skip to content

Fix compatibility with NumPy 2.4: np.trapz and np.in1d removed#739

Merged
kkraus14 merged 3 commits into
NVIDIA:mainfrom
kkraus14:fix-numpy-2.4-trapz-removal
Jan 22, 2026
Merged

Fix compatibility with NumPy 2.4: np.trapz and np.in1d removed#739
kkraus14 merged 3 commits into
NVIDIA:mainfrom
kkraus14:fix-numpy-2.4-trapz-removal

Conversation

@kkraus14

Copy link
Copy Markdown
Contributor

NumPy 2.4 removed np.trapz (deprecated in 2.0, replaced by np.trapezoid) and np.in1d (deprecated in 2.0, replaced by np.isin).

Changes

  • np.trapz overload: Only register when numpy_version < (2, 4)
  • np.trapezoid overload: Keep registration for numpy_version >= (2, 0)
  • Add internal _in1d_impl helper function using @register_jitable
  • np.in1d overload: Only register when numpy_version < (2, 4)
  • Update np.setdiff1d and np.isin to use _in1d_impl instead of np.in1d

This follows the same approach used in numba/numba commits aa7cf35 and c39d72e.

Fixes #726

NumPy 2.4 removed np.trapz (deprecated in 2.0, replaced by np.trapezoid)
and np.in1d (deprecated in 2.0, replaced by np.isin).

Changes:
- np.trapz overload: Only register when numpy_version < (2, 4)
- np.trapezoid overload: Keep registration for numpy_version >= (2, 0)
- Add internal _in1d_impl helper function using @register_jitable
- np.in1d overload: Only register when numpy_version < (2, 4)
- Update np.setdiff1d and np.isin to use _in1d_impl instead of np.in1d

This follows the same approach used in numba/numba commits aa7cf35 and
c39d72e.

Fixes NVIDIA#726
@copy-pr-bot

copy-pr-bot Bot commented Jan 21, 2026

Copy link
Copy Markdown

Auto-sync is disabled for ready for review pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@gmarkall

Copy link
Copy Markdown
Contributor

/ok to test

@greptile-apps

greptile-apps Bot commented Jan 21, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes compatibility with NumPy 2.4 by addressing the removal of deprecated functions np.trapz and np.in1d.

  • Renamed the internal np_trapz function to np_trapezoid to match upstream naming
  • Conditional registration of np.trapz overload only when numpy_version < (2, 4)
  • Added new _in1d_impl internal helper function with @register_jitable decorator that implements the in1d algorithm
  • Conditional registration of np.in1d overload only when numpy_version < (2, 4)
  • Updated np.setdiff1d and np.isin implementations to use _in1d_impl instead of np.in1d

The changes follow the same approach used in upstream numba/numba commits (aa7cf35 and c39d72e) and maintain backward compatibility with older NumPy versions.

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk - it follows proven upstream patterns and maintains backward compatibility
  • The changes are straightforward version compatibility fixes that follow the exact approach used in the upstream numba project. The _in1d_impl implementation is taken from NumPy's source with appropriate attribution. Version checks ensure backward compatibility, and the internal functions are properly marked with @register_jitable.
  • No files require special attention

Important Files Changed

Filename Overview
numba_cuda/numba/cuda/np/arraymath.py Added compatibility for NumPy 2.4 by conditionally registering np.trapz and np.in1d overloads only when NumPy version < 2.4, introduced _in1d_impl internal helper function, and updated setdiff1d and isin to use the internal helper instead of np.in1d.

@greptile-apps

greptile-apps Bot commented Jan 21, 2026

Copy link
Copy Markdown
Contributor

Greptile found no issues!

From now on, if a review finishes and we haven't found any issues, we will not post anything, but you can confirm that we reviewed your changes in the status check section.

This feature can be toggled off in your Code Review Settings by deselecting "Create a status check for each PR".

Comment thread numba_cuda/numba/cuda/np/arraymath.py Outdated
Co-authored-by: Bradley Dice <bdice@bradleydice.com>
@kkraus14

Copy link
Copy Markdown
Contributor Author

/ok to test

@kkraus14
kkraus14 enabled auto-merge (squash) January 21, 2026 19:11

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

1 file reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

Comment thread numba_cuda/numba/cuda/np/arraymath.py Outdated
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
@kkraus14

Copy link
Copy Markdown
Contributor Author

/ok to test a43aafb

@kkraus14
kkraus14 merged commit 6234548 into NVIDIA:main Jan 22, 2026
103 of 105 checks passed
gmarkall added a commit to gmarkall/numba-cuda that referenced this pull request Jan 27, 2026
- Add Python 3.14 to the wheel publishing matrix (NVIDIA#750)
- feat: swap out internal device array usage with `StridedMemoryView` (NVIDIA#703)
- Fix max block size computation in `forall` (NVIDIA#744)
- Fix prologue debug line info pointing to decorator instead of def line (NVIDIA#746)
- Fix kernel return type in DISubroutineType debug metadata (NVIDIA#745)
- Fix missing line info in Jupyter notebooks (NVIDIA#742)
- Fix: Pass correct flags to linker when debugging in the presence of LTOIR code (NVIDIA#698)
- chore(deps): add cuda-pathfinder to pixi deps (NVIDIA#741)
- fix: enable flake8-bugbear lints and fix found problems (NVIDIA#708)
- fix: Fix race condition in CUDA Simulator (NVIDIA#690)
- ci: run tests in parallel (NVIDIA#740)
- feat: users can pass `shared_memory_carveout` to @cuda.jit (NVIDIA#642)
- Fix compatibility with NumPy 2.4: np.trapz and np.in1d removed (NVIDIA#739)
- Pass the -numba-debug flag to libnvvm (NVIDIA#681)
- ci: remove rapids containers from conda ci (NVIDIA#737)
- Use `pathfinder` for dynamic libraries (NVIDIA#308)
- CI: Add CUDA 13.1 testing support (NVIDIA#705)
- Adding `pixi run test` and `pixi run test-par` support (NVIDIA#724)
- Disable per-PR nvmath tests + follow same test practice (NVIDIA#723)
- chore(deps): regenerate pixi lockfile (NVIDIA#722)
- Fix DISubprogram line number to point to function definition line (NVIDIA#695)
- revert: chore(dev): build pixi using rattler (NVIDIA#713) (NVIDIA#719)
- [feat] Initial version of the Numba CUDA GDB pretty-printer (NVIDIA#692)
- chore(dev): build pixi using rattler (NVIDIA#713)
- build(deps): bump the actions-monthly group across 1 directory with 8 updates (NVIDIA#704)
@gmarkall gmarkall mentioned this pull request Jan 27, 2026
kkraus14 pushed a commit that referenced this pull request Jan 28, 2026
- Add Python 3.14 to the wheel publishing matrix (#750)
- feat: swap out internal device array usage with `StridedMemoryView`
(#703)
- Fix max block size computation in `forall` (#744)
- Fix prologue debug line info pointing to decorator instead of def line
(#746)
- Fix kernel return type in DISubroutineType debug metadata (#745)
- Fix missing line info in Jupyter notebooks (#742)
- Fix: Pass correct flags to linker when debugging in the presence of
LTOIR code (#698)
- chore(deps): add cuda-pathfinder to pixi deps (#741)
- fix: enable flake8-bugbear lints and fix found problems (#708)
- fix: Fix race condition in CUDA Simulator (#690)
- ci: run tests in parallel (#740)
- feat: users can pass `shared_memory_carveout` to @cuda.jit (#642)
- Fix compatibility with NumPy 2.4: np.trapz and np.in1d removed (#739)
- Pass the -numba-debug flag to libnvvm (#681)
- ci: remove rapids containers from conda ci (#737)
- Use `pathfinder` for dynamic libraries (#308)
- CI: Add CUDA 13.1 testing support (#705)
- Adding `pixi run test` and `pixi run test-par` support (#724)
- Disable per-PR nvmath tests + follow same test practice (#723)
- chore(deps): regenerate pixi lockfile (#722)
- Fix DISubprogram line number to point to function definition line
(#695)
- revert: chore(dev): build pixi using rattler (#713) (#719)
- [feat] Initial version of the Numba CUDA GDB pretty-printer (#692)
- chore(dev): build pixi using rattler (#713)
- build(deps): bump the actions-monthly group across 1 directory with 8
updates (#704)

<!--

Thank you for contributing to numba-cuda :)

Here are some guidelines to help the review process go smoothly.

1. Please write a description in this text box of the changes that are
being
   made.

2. Please ensure that you have written units tests for the changes
made/features
   added.

3. If you are closing an issue please use one of the automatic closing
words as
noted here:
https://help.github.com/articles/closing-issues-using-keywords/

4. If your pull request is not ready for review but you want to make use
of the
continuous integration testing facilities please label it with `[WIP]`.

5. If your pull request is ready to be reviewed without requiring
additional
work on top of it, then remove the `[WIP]` label (if present) and
replace
it with `[REVIEW]`. If assistance is required to complete the
functionality,
for example when the C/C++ code of a feature is complete but Python
bindings
are still required, then add the label `[HELP-REQ]` so that others can
triage
and assist. The additional changes then can be implemented on top of the
same PR. If the assistance is done by members of the rapidsAI team, then
no
additional actions are required by the creator of the original PR for
this,
otherwise the original author of the PR needs to give permission to the
person(s) assisting to commit to their personal fork of the project. If
that
doesn't happen then a new PR based on the code of the original PR can be
opened by the person assisting, which then will be the PR that will be
   merged.

6. Once all work has been done and review has taken place please do not
add
features or make changes out of the scope of those requested by the
reviewer
(doing this just add delays as already reviewed code ends up having to
be
re-reviewed/it is hard to tell what is new etc!). Further, please do not
rebase your branch on main/force push/rewrite history, doing any of
these
   causes the context of any comments made by reviewers to be lost. If
   conflicts occur against main they should be resolved by merging main
   into the branch used for making the pull request.

Many thanks in advance for your cooperation!

-->
maxymnaumchyk added a commit to maxymnaumchyk/awkward that referenced this pull request Mar 3, 2026
ianna added a commit to scikit-hep/awkward that referenced this pull request Mar 13, 2026
…3894)

* feat: customly overload the reducers that call cuda-compute kernels

* overload reducers only if they are implemented in cuda/reducers.py

* style: pre-commit fixes

* treat complex values in a separate kernel

* style: pre-commit fixes

* import AnyType

* pass starts.data

* add offsets.data as an input to the argmin kernel

* style: pre-commit fixes

* add argmax reducer

* empty commit to rerun the gpu tests

* one more empty commit to rerun the gpu tests

* delete old calls for cuda-compute(cccl) reducer kernels

* style: pre-commit fixes

* delete old cuda_kernels for argmin and argmax

* add suggestions from Ianna

* improvement from Ianna

Co-authored-by: Ianna Osborne <ianna.osborne@cern.ch>

* style: pre-commit fixes

* add suggestions from Ianna

* add AxisNoneReducerMax reducer

* add AxisNoneReducerArgMax reducer

* pass `needs_position: Final` for AxisNone reducers

* pass `needs_position: True` for AxisNoneArgMax reducer only

* try to apply positional corrections for the result of `AxisNoneReducerArgMax`

* pass a superclass directly

* try processing complex numbers as a separate case

* if the two values are equal, keep the index of the FIRST max value we encounter

* add two tests to see if the code path is actually using the overloaded reducers

* style: pre-commit fixes

* style fix

* move `awkward_axis_none_reduce_argmax` to the reducers.py

* add `AxisNoneReducerArgMin`

* correct the parts with comparing the values

* increase numba-cuda version requirement to 0.25. It has this PR NVIDIA/numba-cuda#739, which is now needed for using numpy>2.4

* ignore a `DeprecationWarning` from new `numba-cuda` version for now

* for the equal values always return the one with the lowest index

* Update layout.py

* style: pre-commit fixes

* for now call new cuda.compute kernels from `cupy.py`. They should be moved to `_connect/cuda/reducers.py` in the next PR

* there is no need to return the result from inside the kernels

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Ianna Osborne <ianna.osborne@cern.ch>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] numpy.trapz was removed in numpy 2.4

3 participants