Skip to content

Add error hint when a numpy array is expected? #280

Closed
@IanButterworth

Description

@IanButterworth

I was bitten by

julia> labelled_frame = zeros(Int, 10, 10); labelled_frame[5:6, 5:6] .= 1;

julia> using PythonCall

julia> skimage = pyimport("skimage")
Python module: <module 'skimage' from '/Users/ian/Documents/GitHub/Foo.jl/.CondaPkg/env/lib/python3.11/site-packages/skimage/__init__.py'>

julia> skimage.measure.regionprops(labelled_frame)
ERROR: Python: AttributeError: Julia: type Array has no field dtype
Python stacktrace:
 [1] __getattr__
   @ ~/.julia/packages/PythonCall/dsECZ/src/jlwrap/any.jl:189
 [2] regionprops
   @ skimage.measure._regionprops ~/Documents/GitHub/Foo.jl/.CondaPkg/env/lib/python3.11/site-packages/skimage/measure/_regionprops.py:1253
Stacktrace:
 [1] pythrow()
   @ PythonCall ~/.julia/packages/PythonCall/dsECZ/src/err.jl:94
 [2] errcheck
   @ ~/.julia/packages/PythonCall/dsECZ/src/err.jl:10 [inlined]
 [3] pycallargs(f::Py, args::Py)
   @ PythonCall ~/.julia/packages/PythonCall/dsECZ/src/abstract/object.jl:210
 [4] pycall(f::Py, args::Matrix{Int64}; kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
   @ PythonCall ~/.julia/packages/PythonCall/dsECZ/src/abstract/object.jl:228
 [5] pycall
   @ ~/.julia/packages/PythonCall/dsECZ/src/abstract/object.jl:218 [inlined]
 [6] #_#11
   @ ~/.julia/packages/PythonCall/dsECZ/src/Py.jl:352 [inlined]
 [7] (::Py)(args::Matrix{Int64})
   @ PythonCall ~/.julia/packages/PythonCall/dsECZ/src/Py.jl:352
 [8] top-level scope
   @ REPL[35]:1

which after help on slack was fixed by converting to a numpy array

julia> skimage.measure.regionprops(pyjl(labelled_frame).to_numpy())
Python list: [<skimage.measure._regionprops.RegionProperties object at 0x1194fee60>]

The error itself was not helpful in pointing me in that direction

ERROR: Python: AttributeError: Julia: type Array has no field dtype

Is it possible to guide the user better here? Or at least add this to a troubleshooting section of the docs?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions