Skip to content

Commit d7c69f7

Browse files
committed
test: trapezoid should be used for Numpy >= 2 and trapz otherwise
1 parent 48106e2 commit d7c69f7

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

pint/testsuite/test_numpy.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -440,9 +440,10 @@ def test_cross(self):
440440

441441
# NP2: Remove this when we only support np>=2.0
442442
@helpers.requires_array_function_protocol()
443+
@helpers.requires_numpy_previous_than("2.0")
443444
def test_trapz(self):
444445
helpers.assert_quantity_equal(
445-
np.trapezoid([1.0, 2.0, 3.0, 4.0] * self.ureg.J, dx=1 * self.ureg.m),
446+
np.trapz([1.0, 2.0, 3.0, 4.0] * self.ureg.J, dx=1 * self.ureg.m),
446447
7.5 * self.ureg.J * self.ureg.m,
447448
)
448449

pint/testsuite/test_numpy_func.py

+17
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,24 @@ def test_numpy_wrap(self):
195195
# TODO (#905 follow-up): test that NotImplemented is returned when upcast types
196196
# present
197197

198+
@helpers.requires_numpy_previous_than("2.0")
198199
def test_trapz(self):
200+
with ExitStack() as stack:
201+
stack.callback(
202+
setattr,
203+
self.ureg,
204+
"autoconvert_offset_to_baseunit",
205+
self.ureg.autoconvert_offset_to_baseunit,
206+
)
207+
self.ureg.autoconvert_offset_to_baseunit = True
208+
t = self.Q_(np.array([0.0, 4.0, 8.0]), "degC")
209+
z = self.Q_(np.array([0.0, 2.0, 4.0]), "m")
210+
helpers.assert_quantity_equal(
211+
np.trapz(t, x=z), self.Q_(1108.6, "kelvin meter")
212+
)
213+
214+
@helpers.requires_numpy_at_least("2.0")
215+
def test_trapezoid(self):
199216
with ExitStack() as stack:
200217
stack.callback(
201218
setattr,

0 commit comments

Comments
 (0)