Skip to content

fix: replace removed np.trapz and np.bool APIs - #12

Open
xyf5432 wants to merge 1 commit into
simoncblyth:masterfrom
xyf5432:fix/numpy-api-replacements
Open

fix: replace removed np.trapz and np.bool APIs#12
xyf5432 wants to merge 1 commit into
simoncblyth:masterfrom
xyf5432:fix/numpy-api-replacements

Conversation

@xyf5432

@xyf5432 xyf5432 commented Aug 16, 2026

Copy link
Copy Markdown

Fixes #11

Problem

Two removed numpy APIs are used in this repo:

  • np.trapz — removed in numpy 2.4.0 → AttributeError: module 'numpy' has no attribute 'trapz' on modern numpy
  • np.bool — removed in numpy 1.24.0 → AttributeError: module 'numpy' has no attribute 'bool' on numpy >= 1.24

Fix

  • For np.trapz: add a compat shim in ana/ckn.py and ana/trapz.py that prefers numpy.trapezoid (available since numpy 2.0, identical signature) and falls back to numpy.trapz on numpy < 2.0, so the scripts keep working on every numpy version:
try:
    from numpy import trapezoid as _trapz_impl
except ImportError:
    from numpy import trapz as _trapz_impl
  • For np.bool: use the builtin bool, which numpy accepts as a dtype with identical behavior.
  • Docstring reference, doc URL, and the figure title in ana/trapz.py are updated to the new API name.

Verification

  • np.trapezoid(y, x=None, dx=1.0, axis=-1) has an identical signature to trapz
  • dtype=bool produces identical boolean arrays
  • Verified the shim on numpy 1.26.4 (numpy<2 branch): it selects trapz and computes the expected trapezoidal integral
  • Similar fixes in other downstream projects: gpytorch#2695

np.trapz was removed in numpy 2.4.0 and np.bool in numpy 1.24.0.
Replace trapz calls with a compat shim preferring numpy.trapezoid and
falling back to numpy.trapz on numpy<2, and np.bool with the builtin
bool. Also update the docstring reference, the doc URL and the figure
title in ana/trapz.py to the new API name.
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.

[Compatibility Issue] NumPy API removals: np.trapz + np.bool

1 participant