Skip to content

Conversation

@guitargeek
Copy link
Contributor

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.

One separate commit in this PR fixes an unnecessary warning when configuring ROOT in an environment without Keras installed.

Another separate commit is fixing up the code of the updated test to make the ruff linter happy.

 962/3718 Test   https://github.com/root-project/root/pull/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

The Keras version check that was introduced in 2ddaee3 should only be
done if Keras is found. Otherwise, we get wrong warnings about how the
Keras version could not be determined
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   root-project#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

```
Code-formatting with black to make the ruff linter happy.
@guitargeek guitargeek added the pr:emergency🚨 This PR is fixing breakage, it's urgent and may overtake others label Dec 23, 2025
@guitargeek guitargeek self-assigned this Dec 23, 2025
@github-actions
Copy link

Test Results

    22 files      22 suites   3d 20h 46m 3s ⏱️
 3 794 tests  3 794 ✅ 0 💤 0 ❌
80 325 runs  80 325 ✅ 0 💤 0 ❌

Results for commit 63a817f.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr:emergency🚨 This PR is fixing breakage, it's urgent and may overtake others

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant