Skip to content

support __array__(dtype=...) optional argument #160

Closed
@stevengj

Description

@stevengj

From JuliaPy/PythonPlot.jl#8:

julia> np = pyimport("numpy");

julia> y = range(-5,5,length=11)
-5.0:1.0:5.0

julia> np.asarray(y)
Python ndarray: array([-5., -4., -3., -2., -1.,  0.,  1.,  2.,  3.,  4.,  5.])

julia> np.asarray(y, dtype=np.float64)
ERROR: Python: TypeError: ArrayValue.__array__() takes 1 positional argument but 2 were given
Python stacktrace: none
Stacktrace:
 [1] pythrow()
   @ PythonCall ~/.julia/packages/PythonCall/XgP8G/src/err.jl:94
 [2] errcheck
   @ ~/.julia/packages/PythonCall/XgP8G/src/err.jl:10 [inlined]
 [3] pycallargs
   @ ~/.julia/packages/PythonCall/XgP8G/src/abstract/object.jl:154 [inlined]
 [4] pycall(f::Py, args::StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64}; kwargs::Base.Pairs{Symbol, Py, Tuple{Symbol}, NamedTuple{(:dtype,), Tuple{Py}}})
   @ PythonCall ~/.julia/packages/PythonCall/XgP8G/src/abstract/object.jl:165
 [5] #_#11
   @ ~/.julia/packages/PythonCall/XgP8G/src/Py.jl:360 [inlined]
 [6] top-level scope
   @ REPL[26]:1

It seems like you need to support the dtype optional argument in this method: https://github.com/cjdoris/PythonCall.jl/blob/b4528b71e9878c8a71b9bd48ff759b5d5b14267f/src/jlwrap/array.jl#L317-L326

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