Skip to content

Commit 4eb77e1

Browse files
committed
Fix numpy.trapz deprecation: use scipy.integrated.trapezoid instead
1 parent 10c567c commit 4eb77e1

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

plotpy/tests/features/test_computations.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,18 @@
77

88
# guitest: show
99

10+
import numpy as np
11+
import scipy.integrate as spt
1012
from guidata.qthelpers import qt_app_context
11-
from numpy import linspace, sin, trapz
1213

1314
from plotpy.builder import make
1415
from plotpy.tests import vistools as ptv
1516

1617

1718
def test_computations():
1819
"""Test computations"""
19-
x = linspace(-10, 10, 1000)
20-
y = sin(sin(sin(x)))
20+
x = np.linspace(-10, 10, 1000)
21+
y = np.sin(np.sin(np.sin(x)))
2122
with qt_app_context(exec_loop=True):
2223
curve = make.curve(x, y, "ab", "b")
2324
range = make.range(-2, 2)
@@ -26,7 +27,7 @@ def test_computations():
2627
)
2728

2829
disp1 = make.computation(
29-
range, "BL", "trapz=%g", curve, lambda x, y: trapz(y, x)
30+
range, "BL", "trapz=%g", curve, lambda x, y: spt.trapezoid(y, x)
3031
)
3132

3233
disp2 = make.computations(

plotpy/tools/curve.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from typing import TYPE_CHECKING, Any, Callable
88

99
import numpy as np
10+
import scipy.integrate as spt
1011
from guidata.dataset import ChoiceItem, DataSet, FloatItem, IntItem
1112
from guidata.qthelpers import execenv
1213
from guidata.widgets.arrayeditor import ArrayEditor
@@ -102,8 +103,12 @@ def move(self, filter: StatefulEventFilter, event: QG.QMouseEvent) -> None:
102103
),
103104
(curve, "<y>=%g", lambda *args: args[1].mean()),
104105
(curve, "σ(y)=%g", lambda *args: args[1].std()),
105-
(curve, "∑(y)=%g", lambda *args: np.trapz(args[1])),
106-
(curve, "∫ydx=%g", lambda *args: np.trapz(args[1], args[0])),
106+
(curve, "∑(y)=%g", lambda *args: spt.trapezoid(args[1])),
107+
(
108+
curve,
109+
"∫ydx=%g",
110+
lambda *args: spt.trapezoid(args[1], args[0]),
111+
),
107112
],
108113
)
109114
self.label.attach(plot)

0 commit comments

Comments
 (0)