Using functions loaded via pycall (kwargs)

The problem is probably that a dictionary mapping strings to values is not allowed for keyword arguments in Julia — if you want to splat, it needs to be something like a NamedTuple, or a dictionary mapping symbols to values.

One option here would be to simply pass the keyword arguments explicitly rather than trying to splat them:

estimate = fit_model.estimate(ydata, xdata)
fit_result = fit_model.fit(data=ydata, x=xdata, offset=estimate["offset"], amplitude=estimate["amplitude"])

Another option would be to make sure you treat the returned dictionary as having symbols for keys. You can do this via the lower-level function pycall, which lets you specify the desired function return type. For example:

estimate = pycall(fit_model.estimate, PyDict{Symbol,PyAny}, ydata, xdata)
fit_result = fit_model.fit(; data=ydata, x=xdata, estimate...)

The basic lesson here is that you need to understand how Python types relate to Julia types, and you sometimes need to specify the desired type conversion explicitly rather than relying on PyCall’s auto-conversion.

(Another package, PythonCall.jl, never auto-converts Python objects to native Julia types at all, so you always have to convert explicitly.)

2 Likes