-
Notifications
You must be signed in to change notification settings - Fork 188
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
handling arrays with missing values (with possible solution) #616
Comments
Would it be useful to make a pull request adding this function? Fixing deprecated function calls, this is what I currently use: using PyCall
using PyCall: PyObject
# allow for plotting with missing values
function PyObject(a::Array{Union{T,Missing},N}) where {T,N}
numpy_ma = PyCall.pyimport("numpy").ma
pycall(numpy_ma.array, Any, coalesce.(a,zero(T)), mask=ismissing.(a))
end |
This is a good idea. In a simple first case, adding the PyObject method to PyPlot would be a PyPlot pull request. This works when it is defined in the user's scope, but not inside the PyPlot module. using PyCall
using PyCall: PyObject
# extend PyObject to maskedarray to allow for plotting with missing values
function PyObject(a::Array{Union{T,Missing},N}) where {T,N}
numpy_ma = PyCall.pyimport("numpy").ma
pycall(numpy_ma.array, Any, coalesce.(a,zero(T)), mask=ismissing.(a))
end # test missing support
using PyPlot
x = [missing, 1, 2, 3, 4]
y = [1, 2, missing, 2, 3]
plot(x, y, marker=".") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I would like to plot (with PyPlot) an array containing missing values:
Unfortunately, I get the following error with PyCall v1.18.5, PyPlot v2.6.3 and Julia v1.0.1:
However, if declare the following convertion rule in PyCall, the plotting works:
The function
PyCall
creates essentially a numpy masked array. All missing values are replaced by zero and a mask is given to indicate which values are missing.Can this be added to PyCall?
The text was updated successfully, but these errors were encountered: