Skip to content

Avoid implicit array -> scalar conversion in tests (numpy 2.4)#205

Open
wishstudio wants to merge 1 commit intobmcage:masterfrom
wishstudio:master
Open

Avoid implicit array -> scalar conversion in tests (numpy 2.4)#205
wishstudio wants to merge 1 commit intobmcage:masterfrom
wishstudio:master

Conversation

@wishstudio
Copy link
Copy Markdown

Many tests fail with numpy 2.4

_____________________ TestCVodeReturn.test_jac_error_late ______________________
TypeError: only 0-dimensional arrays can be converted to Python scalars

The above exception was the direct cause of the following exception:

self = <odes.tests.test_user_return_vals_cvode.TestCVodeReturn testMethod=test_jac_error_late>

    def test_jac_error_late(self):
        solver = ode(self.solvername, complex_rhs, jacfn=jac_error_late, old_api=False)
>       soln = solver.solve([0, 1], [1])
               ^^^^^^^^^^^^^^^^^^^^^^^^^

src/scikits/odes/tests/test_user_return_vals_cvode.py:243:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/nix/store/wyl71rbgix5j7lm559zm79raxwdif8fk-python3.13-scikits.odes-3.1.1/lib/python3.13/site-packages/scikits_odes/ode.py:177: in solve
    return self._integrator.solve(tspan, y0)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
src/scikits_odes_sundials/cvode.pyx:1819: in scikits_odes_sundials.cvode.CVODE.solve
    ???
src/scikits_odes_sundials/cvode.pyx:1857: in scikits_odes_sundials.cvode.CVODE._solve
    ???
src/scikits_odes_sundials/cvode.pyx:1383: in scikits_odes_sundials.cvode.CVODE._init_step
    ???
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

t = 0.0, y = array([1.]), ydot = array([1.])

    def complex_rhs(t, y, ydot):
>       ydot[0] = t - y
        ^^^^^^^
E       ValueError: setting an array element with a sequence.

src/scikits/odes/tests/test_user_return_vals_cvode.py:11: ValueError

This patch fixes the problem by using array[0] explicitly.

With numpy 2.4, it complains:

TypeError: only 0-dimensional arrays can be converted to Python scalars
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant