-
Notifications
You must be signed in to change notification settings - Fork 67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Python: TypeError: Object of type DictValue is not JSON serializable #491
Comments
Furthermore, using |
Hi there, I am back here. I think in the end this is NOT an issue with PythonCall.jl. I restored the old PyCall.jl code. It also doesn't worrk and errors with a similar error:
notice the different type |
Hm, but in the Is there a way to truly pass in an actualy Python dictionry to the call |
OK so for clarity the issue you're seeing is that Julia
So you'll need to ensure that the object you're serialising is only composed of Python native types all the way down. |
Another option is that if you can control the JSON serialiser class being used then you could write your own which handles |
Hi, thanks for the reply, but I admit I am rather confused now... Isn't one of the things PythonCall.jl does to convert Julia data into Python data when I am calling the function? Here this isn't really happening, because If I was passing in Python data they would be serialized correctly, as the python code actually works. What am I missing here? Why would calling a |
For what its worth, what you said of explicitly converting everything, did work: function to_python(x)
if x isa AbstractArray
return PythonCall.pybuiltins.list(x)
elseif x isa AbstractDict
return PythonCall.pybuiltins.dict(x)
else
return PythonCall.Py(x)
end
end
config = Dict(k => to_python(x) for (k, x) in config)
config = PythonCall.pybuiltins.dict(config) and I don't get any errors. |
It converts Julia objects to Python objects yes, but not necessarily to the types you might expect - in particular a Julia |
I'm glad you got something working. I'll point out you can also use |
Affects: PythonCall
Describe the bug
I am converting some old code I had with PyCall.jl to PythonCall.jl. Unfortunately, the PythonCall version does not work and gives error:
I am not sure how easy it is to make a MWE, as it requires downloading some climate data from copernicus that requires an account. Here is the setup I have:
installation:
then I must make a dictionary that stores the configuration options for what data to download. I do this using something like:
then, I download the data by calling the command:
I also tried without wrapping the config to
Py
, but I got the same error.Exactly the same piece of code worked with PyCall (with the same
pyimport
statement.I am not sure what the problem is or what the bug is. I am happy to help to solve this if you need more information
Here I am attaching the Python code version that would work, and comes from this webpage.
Your system
Please provide detailed information about your system:
Conda status:
The text was updated successfully, but these errors were encountered: