Skip to content

SciPy should be added as optional dependency #264

@iyanmv

Description

@iyanmv

It is used in this function:

def _trapz(y, x, dx, axis):
"""ported from numpy 1.26 since it will be deprecated and removed"""
try:
# if scipy is available, we use it
from scipy.integrate import trapezoid # type: ignore
except ImportError:
# otherwise we use the implementation ported from numpy 1.26
from numpy.core.numeric import asanyarray
from numpy.core.umath import add
y = asanyarray(y)
if x is None:
d = dx
else:
x = asanyarray(x)
if x.ndim == 1:
d = diff(x)
# reshape to correct shape
shape = [1]*y.ndim
shape[axis] = d.shape[0]
d = d.reshape(shape)
else:
d = diff(x, axis=axis)
nd = y.ndim
slice1 = [slice(None)]*nd
slice2 = [slice(None)]*nd
slice1[axis] = slice(1, None)
slice2[axis] = slice(None, -1)
try:
ret = (d * (y[tuple(slice1)] + y[tuple(slice2)]) / 2.0).sum(axis)
except ValueError:
# Operations didn't work, cast to ndarray
d = np.asarray(d)
y = np.asarray(y)
ret = add.reduce(d * (y[tuple(slice1)]+y[tuple(slice2)])/2.0, axis)
return ret
else:
return trapezoid(y, x=x, dx=dx, axis=axis)

But it is not included in [project.optional-dependencies].

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions