Skip to content

Update np.trapz to np.trapezoid#10329

Closed
mscheltienne wants to merge 3 commits intonumba:mainfrom
mscheltienne:trapz
Closed

Update np.trapz to np.trapezoid#10329
mscheltienne wants to merge 3 commits intonumba:mainfrom
mscheltienne:trapz

Conversation

@mscheltienne
Copy link
Copy Markdown
Contributor

On our CI job running pre-release version of numpy and numba (installed from main):

✔︎ numba:                  0.63.0b1+96.ge18468b40
✔︎ numpy (<3,>=1.23):      2.4.0.dev0

We see:

.venv/lib/python3.13/site-packages/numba/core/dispatcher.py:443: in _compile_for_args
    raise e
.venv/lib/python3.13/site-packages/numba/core/dispatcher.py:376: in _compile_for_args
    return_val = self.compile(tuple(argtypes))
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.venv/lib/python3.13/site-packages/numba/core/dispatcher.py:908: in compile
    cres = self._compiler.compile(args, return_type)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.venv/lib/python3.13/site-packages/numba/core/dispatcher.py:80: in compile
    status, retval = self._compile_cached(args, return_type)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.venv/lib/python3.13/site-packages/numba/core/dispatcher.py:94: in _compile_cached
    retval = self._compile_core(args, return_type)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.venv/lib/python3.13/site-packages/numba/core/dispatcher.py:107: in _compile_core
    cres = compiler.compile_extra(self.targetdescr.typing_context,
.venv/lib/python3.13/site-packages/numba/core/compiler.py:737: in compile_extra
    pipeline = pipeline_class(typingctx, targetctx, library,
.venv/lib/python3.13/site-packages/numba/core/compiler.py:396: in __init__
    targetctx.refresh()
.venv/lib/python3.13/site-packages/numba/core/base.py:267: in refresh
    self.load_additional_registries()
.venv/lib/python3.13/site-packages/numba/core/cpu.py:76: in load_additional_registries
    from numba.np import linalg, arraymath, arrayobj # noqa F401
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.venv/lib/python3.13/site-packages/numba/np/arraymath.py:2225: in <module>
    @overload(np.trapz)
              ^^^^^^^^
.venv/lib/python3.13/site-packages/numpy/__init__.py:792: in __getattr__
    raise AttributeError(f"module {__name__!r} has no attribute {attr!r}")
E   AttributeError: module 'numpy' has no attribute 'trapz'. Did you mean: 'trace'

The change line 2247-2249 in arraymath.py doesn't seem to be sufficient:

# numpy 2.0 rename np.trapz to np.trapezoid
if numpy_version >= (2, 0):
    overload(np.trapezoid)(np_trapz)

@DrTodd13
Copy link
Copy Markdown
Contributor

@mscheltienne Thanks for the pull request. We think there needs to be a couple changes. Both trapz and trapezoid exist at the same time in some of the NumPy version so we need to treat them differently. The overload and tests for trapz should exist up until the NumPy version from which it was eliminated and similarly for trapezoid there should be a separate overload and tests that start from the NumPy version from which it was first introduced.

@DrTodd13 DrTodd13 added 4 - Waiting on author Waiting for author to respond to review NumPy 2.0 Related to NumPy 2.0 support labels Nov 18, 2025
@JesseLivezey
Copy link
Copy Markdown

AFAICT, trapz() was deprecated and trapezoid() was added in numpy 2.0. trapz() will be removed in numpy 2.4.

Maint branch of numpy 1.26
https://github.com/numpy/numpy/blob/efcc645601bdce30e24ec58bf447d77a4a849619/numpy/lib/function_base.py#L4860

Maint branch of numpy 2.0
trapz() exists and calls trapezoid()
https://github.com/numpy/numpy/blob/3b89059888c93f1950e1bc9b6d046af494e39afb/numpy/lib/_function_base_impl.py#L5212
same for numpy 2.3
https://github.com/numpy/numpy/blob/285ab2a655f993e51c3f55fd2ca9f92012a18322/numpy/lib/_function_base_impl.py#L5112

trapz() was removed leading up to numpy 2.4
numpy/numpy#29997

@mscheltienne
Copy link
Copy Markdown
Contributor Author

mscheltienne commented Nov 21, 2025

@DrTodd13 Is that better? I'm not familiar with numba's implementation / patterns, so guidance would be appreciated to properly resolve this deprecation.

Copy link
Copy Markdown
Contributor

@DrTodd13 DrTodd13 left a comment

Choose a reason for hiding this comment

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

It looks fine to me but there will be another review by the code owner.

@esc
Copy link
Copy Markdown
Member

esc commented Jan 15, 2026

The commits from this PR were cherry-picked in #10393 and merged to main -- closing now. @mscheltienne your attribution on those commits remains, so thank you for your contribution.

@esc esc closed this Jan 15, 2026
@mscheltienne mscheltienne deleted the trapz branch January 15, 2026 09:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

4 - Waiting on author Waiting for author to respond to review NumPy 2.0 Related to NumPy 2.0 support

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants