-
Notifications
You must be signed in to change notification settings - Fork 88
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
Plotting DataArrays #262
Comments
I have seen that other conversion rules (e.g. from range to 1d array) are already present: I could try to make a pull request, developers agree to have DataArrays as an additional dependencies. |
Or with NullableArrays using NullableArrays
using PyPlot
using PyCall
@pyimport numpy.ma as ma
# convert Julia's NullableArrays to Numpy's masked array
na2pyma(S) = pycall(ma.array, Any, S.values, mask=S.isnull)
PyPlot.pcolor(x,y,z::NullableArray; kws...) = pcolor(x,y,na2pyma(z); kws...)
PyPlot.pcolor(z::NullableArray; kws...) = pcolor(na2pyma(z); kws...) Test with: a = randn(10,10); X = NullableArray(a, a .> 1.7)
pcolor(X) |
It would be cleaner to simply define However, it would be nicer to do this if we can define a small package (required by PyCall, DataArrays, and NullableArrays) that defines a common API, something like module AbstractMissingData
export ismissing, densevalues, missingvalues
ismissing(a) = Val{false}() # default fallback is no missing data
ismissing(a, i::Integer...) = false
densevalues(a) = a
missingvalues(a) = falses(a)
end Then e.g. import AbstractMissingData
MissingData.ismissing(a::NullableArray) = Val{true}()
Base.@propagate_inbounds MissingData.ismissing(a::NullableArray, i::Integer...) = a.isnull[i...]
MissingData.densevalues(a::NullableArray) = a.values
MissingData.missingvalues(a::NullableArray) = a.isnull and similarly for DataArrays. PyCall could then define something like e.g.
and it would work for both NullableArrays and DataArrays without introducing a dependency on those packages. |
cc: @davidagold |
These functions kind of already exist in NullableArrays: they are |
@nalimilan, it would be good to have a solution that worked for DataArrays too. The point is you don't need to move the functionality into a small package, you just need to move the interface into a small package, so that all interested packages can use the same interface without depending on one another. |
I am new to Julia and I asked initially for DataArrays because it was the first package that I found to represent missing data. However, it seems that the development efforts is now going into NullableArrays. I would already be happy with a solution that works with NullableArrays. The proposed solution to use a constructor function is indeed way more elegant than what I proposed. using NullableArrays
using PyPlot
using PyCall
@pyimport numpy.ma as ma
PyObject(a::NullableArray) = pycall(ma.array, Any, a.values, mask=a.isnull)
a = randn(10,10); X = NullableArray(a, a .> 1.7)
# just pcolor(X) does not work
pcolor(PyObject(X)) Thank you very much for your insight so far on this issue! |
@stevengj Well, yeah, my solution required depending on DataArrays. That idea of a generic interface is certainly worth discussing. We could also include it in AbstractTables to avoid creating yet another small interface package. |
Better use |
It would be great if PyPlot would also support Julia's DataArray and map them internally to numpy's masked arrays.
For
pcolor
I use the following to add the functionality myself.In my domain (geospatial data analysis), it is quite common to have missing data and it would be very useful if this kind of functionality would already be present in PyPlot.
The text was updated successfully, but these errors were encountered: