Skip to content
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

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

Closed
stevengj opened this issue Apr 15, 2022 · 1 comment
Closed

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

stevengj opened this issue Apr 15, 2022 · 1 comment

Comments

@stevengj
Copy link
Member

stevengj commented Apr 15, 2022

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

@cjdoris
Copy link
Collaborator

cjdoris commented Apr 21, 2022

Done on main.

@cjdoris cjdoris closed this as completed Apr 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants