JuliaPy / JuliaPy/PyCall.jl

Type conversion of `masked_array` in `numpy.ma`

Open
#243 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Julia
Stars
1.5k
Forks
186
PR merge metrics
No merged PRs in 30d

Description

Also described in my question in StackOverflow: [How to create a masked array using numpy.ma imported by PyCall in Julia](http://stackoverflow.com/questions/35709042/how-to-create-a-masked-array-using-numpy-ma-imported-by-pycall-in-julia/35710432#35710432)

I was trying to create a `masked_array` Python object with `numpy.ma`.

``` julia
using PyCall
@pyimport numpy.ma as ma
x = ma.masked_equal([0, 1, 0, 2, 3], 0)
ma.is_masked(x)
```

The output, however, is just a Julia array.

```julia
julia> x = ma.masked_equal([0, 1, 0, 2, 3], 0)
5-element Array{Int64,1}:
0
1
0
2
3
julia> ma.is_masked(x)
false
```

The correct output can be obtained by using `pycall()` (thank Matt B. for pointing it out in my stackoverflow question):

```julia
julia> x = pycall(ma.masked_equal, Any, [0,1,0,2,3], 0)
PyObject masked_array(data = [-- 1 -- 2 3],
mask = [ True False True False False],
fill_value = 0)
julia> ma.is_masked(x)
true
```

It happens because PyCall considers the `masked_array` as just a usual array.

```julia
julia> pytype_query(x)
Array{Int64,N}
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.