82 lines
3.5 KiB
Diff
82 lines
3.5 KiB
Diff
From d5135f7869406396b3ba8e944c71dbdd67d3ea01 Mon Sep 17 00:00:00 2001
|
|
From: Jonas Rembser <jonas.rembser@cern.ch>
|
|
Date: Tue, 23 Dec 2025 19:04:45 +0100
|
|
Subject: [PATCH] [Python] Fix TF1 Pythonization test for NumPy 2.4.0
|
|
|
|
The new NumPy 2.4.0 is more strict when implicitly converting 1-element
|
|
arrays to scalars. It doesn't do that anymore, causing the TF1
|
|
Pythonization tests to fail (see log below).
|
|
|
|
This actually pointed to a real mistake in setting up the test, where a
|
|
2D array was used to define the TFormula parameters while it should be a
|
|
1D array.
|
|
|
|
```txt
|
|
962/3718 Test #93: pyunittests-bindings-pyroot-pythonizations-pyroot-pyz-tf-pycallables ..............................***Failed 3.05 sec
|
|
test_callable (tf_pycallables.TF1.test_callable)
|
|
Test function provided as callable ... ok
|
|
test_evalpar (tf_pycallables.TF1.test_evalpar)
|
|
Test the 2D Numpy array pythonizations for TF1::EvalPar ... ERROR
|
|
test_evalpar_dynamic (tf_pycallables.TF1.test_evalpar_dynamic)
|
|
Test the 2D NumPy pythonizations with dynamic TF1 data dimensions ... ok
|
|
test_fitgauss (tf_pycallables.TF1.test_fitgauss)
|
|
Test fitting a histogram to a Python function ... ok
|
|
test_identity (tf_pycallables.TF1.test_identity)
|
|
Test simple function without parameters ... ok
|
|
test_params (tf_pycallables.TF1.test_params)
|
|
Test function with parameters ... ok
|
|
test_params (tf_pycallables.TF2.test_params)
|
|
Test function with parameters ... ok
|
|
test_params (tf_pycallables.TF3.test_params)
|
|
Test function with parameters ... ok
|
|
|
|
======================================================================
|
|
ERROR: test_evalpar (tf_pycallables.TF1.test_evalpar)
|
|
Test the 2D Numpy array pythonizations for TF1::EvalPar
|
|
----------------------------------------------------------------------
|
|
Traceback (most recent call last):
|
|
File "/github/home/ROOT-CI/src/bindings/pyroot/pythonizations/test/tf_pycallables.py", line 129, in test_evalpar
|
|
expected_value = pyf_tf1_coulomb(x[i, ::2], params)
|
|
File "/github/home/ROOT-CI/src/bindings/pyroot/pythonizations/test/tf_pycallables.py", line 33, in pyf_tf1_coulomb
|
|
return p[1] * x[0] * x[1] / (p[0]**2) * math.exp(-p[2] / p[0])
|
|
~~~~~~~~^^^^^^^^^^^^^^
|
|
TypeError: only 0-dimensional arrays can be converted to Python scalars
|
|
|
|
----------------------------------------------------------------------
|
|
Ran 8 tests in 1.469s
|
|
|
|
FAILED (errors=1)
|
|
CMake Error at /github/home/ROOT-CI/src/cmake/modules/RootTestDriver.cmake:232 (message):
|
|
error code: 1
|
|
|
|
```
|
|
---
|
|
.../pyroot/pythonizations/test/tf_pycallables.py | 12 +++++++-----
|
|
1 file changed, 7 insertions(+), 5 deletions(-)
|
|
|
|
diff --git a/bindings/pyroot/pythonizations/test/tf_pycallables.py b/bindings/pyroot/pythonizations/test/tf_pycallables.py
|
|
index 2a7d6b72462..5a223030ec9 100644
|
|
--- a/bindings/pyroot/pythonizations/test/tf_pycallables.py
|
|
+++ b/bindings/pyroot/pythonizations/test/tf_pycallables.py
|
|
@@ -116,11 +116,13 @@ class TF1(unittest.TestCase):
|
|
[3.0, 10, 4.0]
|
|
])
|
|
|
|
- params = np.array([
|
|
- [1.0], # Distance between charges r
|
|
- [8.99e9], # Coulomb constant k (in N·m²/C²)
|
|
- [0.1] # Additional factor for modulation
|
|
- ])
|
|
+ params = np.array(
|
|
+ [
|
|
+ 1.0, # Distance between charges r
|
|
+ 8.99e9, # Coulomb constant k (in N·m²/C²)
|
|
+ 0.1, # Additional factor for modulation
|
|
+ ]
|
|
+ )
|
|
|
|
# Slice to avoid the dummy column of 10's
|
|
res = rtf1_coulomb.EvalPar(x[:, ::2], params)
|
|
--
|
|
2.52.0
|
|
|