Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions braintools/visualize/_statistical.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
from braintools._misc import set_module_as
from braintools.tree import as_numpy

# ``np.trapz`` was renamed to ``np.trapezoid`` in NumPy 2.0 and removed
# outright in NumPy 2.4, so resolve whichever name the installed NumPy
# provides (falling back to ``np.trapz`` for NumPy < 2.0).
_trapezoid = getattr(np, 'trapezoid', None) or np.trapz

__all__ = [
'correlation_matrix',
'distribution_plot',
Expand Down Expand Up @@ -922,7 +927,7 @@ def roc_curve(
fpr = np.array(fpr)

# Calculate AUC
auc = np.trapz(tpr, fpr)
auc = _trapezoid(tpr, fpr)

# Plot ROC curve
ax.plot(fpr, tpr, color=color, linewidth=2, label=f'AUC = {auc:.3f}', **kwargs)
Expand Down Expand Up @@ -1003,7 +1008,7 @@ def precision_recall_curve(
recall = np.array(recall)

# Calculate average precision
ap = np.trapz(precision, recall)
ap = _trapezoid(precision, recall)

# Plot PR curve
ax.plot(recall, precision, color=color, linewidth=2,
Expand Down
3 changes: 3 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ assets are migrated to the new `brainx.chaobrain.com` host.
- `remove_axis` uses `ax.spines` instead of the non-existent `ax.spine` (#96).
- `create_neural_colormap` / `brain_colormaps` register with `force=True`,
making them idempotent rather than raising on re-use (#97).
- `roc_curve` / `precision_recall_curve` resolve `np.trapezoid` when
available (falling back to `np.trapz`), fixing an `AttributeError` on
NumPy >= 2.4 where `np.trapz` was removed (#99).

### Infrastructure

Expand Down
Loading