Skip to content

Commit a277d5e

Browse files
Fix remaining PythonCall type conversions
Convert all Python statistics fields (nfev, njev, nit, function_calls, iterations) to Julia Int using pyconvert instead of direct Int() constructor. Also convert u_root from Python Float to Julia Float64 in SciPyRootScalar. Fixes: - MethodError: Cannot convert PythonCall.Py to Int64 in NLStats - MethodError: no method matching ndims(::PythonCall.Py) in build_solution 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 6c17a16 commit a277d5e

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

lib/NonlinearSolveSciPy/src/NonlinearSolveSciPy.jl

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -159,12 +159,17 @@ function SciMLBase.__solve(
159159
u = prob.u0 isa Number ? u_vec[1] : reshape(u_vec, size(prob.u0))
160160

161161
ret = pyconvert(Bool, res.success) ? SciMLBase.ReturnCode.Success : SciMLBase.ReturnCode.Failure
162+
nfev = try
163+
pyconvert(Int, res.nfev)
164+
catch
165+
0
166+
end
162167
njev = try
163-
Int(res.njev)
168+
pyconvert(Int, res.njev)
164169
catch
165170
0
166171
end
167-
stats = SciMLBase.NLStats(res.nfev, njev, 0, 0, res.nfev)
172+
stats = SciMLBase.NLStats(nfev, njev, 0, 0, nfev)
168173

169174
return SciMLBase.build_solution(prob, alg, u, resid; retcode = ret,
170175
original = res, stats = stats)
@@ -199,15 +204,13 @@ function SciMLBase.__solve(prob::SciMLBase.NonlinearProblem, alg::SciPyRoot;
199204

200205
ret = pyconvert(Bool, res.success) ? SciMLBase.ReturnCode.Success : SciMLBase.ReturnCode.Failure
201206
nfev = try
202-
Int(res.nfev)
207+
pyconvert(Int, res.nfev)
203208
catch
204-
;
205209
0
206210
end
207211
niter = try
208-
Int(res.nit)
212+
pyconvert(Int, res.nit)
209213
catch
210-
;
211214
0
212215
end
213216
stats = SciMLBase.NLStats(nfev, 0, 0, 0, niter)
@@ -234,20 +237,18 @@ function CommonSolve.solve(prob::SciMLBase.IntervalNonlinearProblem, alg::SciPyR
234237
xtol = abstol,
235238
scipy_kwargs...)
236239

237-
u_root = res.root
240+
u_root = pyconvert(Float64, res.root)
238241
resid = f(u_root, p)
239242

240243
ret = pyconvert(Bool, res.converged) ? SciMLBase.ReturnCode.Success : SciMLBase.ReturnCode.Failure
241244
nfev = try
242-
Int(res.function_calls)
245+
pyconvert(Int, res.function_calls)
243246
catch
244-
;
245247
0
246248
end
247249
niter = try
248-
Int(res.iterations)
250+
pyconvert(Int, res.iterations)
249251
catch
250-
;
251252
0
252253
end
253254
stats = SciMLBase.NLStats(nfev, 0, 0, 0, niter)

0 commit comments

Comments
 (0)