Skip to content

Commit 16f8db8

Browse files
committed
global trap function
1 parent 8250245 commit 16f8db8

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

dascore/transform/integrate.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
patch_function,
1717
)
1818

19+
_TRAP_FUNC = getattr(np, "trapezoid" if hasattr(np, "trapezoid") else "trapz")
20+
1921

2022
def _quasi_mean(array):
2123
"""Get a quasi mean value from an array. Works with datetimes."""
@@ -45,13 +47,11 @@ def _get_new_coords_and_array(patch, array, dims):
4547
ndims = len(patch.shape)
4648
for dxs_or_val, ax in zip(dxs_or_vals, axes):
4749
# Numpy 2/3 compat code
48-
trap_name = "trapezoid" if hasattr(np, "trapezoid") else "trapz"
49-
trap = getattr(np, trap_name)
5050
indexer = broadcast_for_index(ndims, ax, None, fill=slice(None))
5151
if is_array(dxs_or_val):
52-
array = trap(array, x=dxs_or_val, axis=ax)[indexer]
52+
array = _TRAP_FUNC(array, x=dxs_or_val, axis=ax)[indexer]
5353
else:
54-
array = trap(array, dx=dxs_or_val, axis=ax)[indexer]
54+
array = _TRAP_FUNC(array, dx=dxs_or_val, axis=ax)[indexer]
5555
array, coords = _get_new_coords_and_array(patch, array, dims)
5656
return array, coords
5757

0 commit comments

Comments
 (0)