File: 0020-Use-numpy.sum-instead-of-sum-to-fix-test-with-Python.patch

package info (click to toggle)
opm-common 2024.10%2Bds-5
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 98,420 kB
  • sloc: cpp: 263,013; python: 3,155; sh: 198; xml: 174; pascal: 136; makefile: 12
file content (30 lines) | stat: -rw-r--r-- 1,247 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
From: Markus Blatt <markus@dr-blatt.de>
Date: Sun, 9 Feb 2025 18:06:57 +0100
Subject: Use numpy.sum instead of sum to fix test with Python 3.12 (Closes:
 #1095362)

The sum function in Python 3.12 switched to using Neumaier summation
for floats for better accuracy.This broke on of the unit tests.
With this change we use numpy.sum to fix the failing test,
which still uses the not so accurate summation algorithm of sum in
Python 3.11
---
 python/tests/test_emodel.py | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/python/tests/test_emodel.py b/python/tests/test_emodel.py
index ce6439b..6458c11 100755
--- a/python/tests/test_emodel.py
+++ b/python/tests/test_emodel.py
@@ -48,7 +48,10 @@ class TestEModel(unittest.TestCase):
 
         refVol1 = 2.79083e8
 
-        self.assertTrue( abs((sum(celvol1) - refVol1)/refVol1) < 1.0e-5)
+        # The algorithm for sum in Python 3.12 changed to Neumaier summatio
+        # which breaks the following test. Using numpy.sum now to get the
+        # old behaviour. For 3.11 they yield the same result.
+        self.assertTrue( abs((np.sum(celvol1) - refVol1)/refVol1) < 1.0e-5)
 
         mod1.add_filter("EQLNUM","eq", 1);
         mod1.add_filter("DEPTH","lt", 2645.21);