Make `to_numpy` conversions consistent with NumPy `dtype`
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 35/100
Direzione di ricerca
Inizia dall’implementazione collegata di to_numpy() in src/JlWrap/array.jl, quindi confronta la gestione dei vettori annidati con gli esempi NumPy nell’issue. Il lavoro è completato quando gli array di interi annidati producono valori di dtype coerenti con NumPy, inclusi i casi a due e tre dimensioni descritti qui.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Moved discussion in #462 into this separate issue.
Other PythonCall issues related to NumPy dtype and Numpy arrays that may be relevant:
- #319
- #439
- #441
- #486
My system details (click to expand)
Julia
julia> versioninfo()
Julia Version 1.12.1
Commit ba1e628ee49 (2025-10-17 13:02 UTC)
Build Info:
Official https://julialang.org release
Platform Info:
OS: Linux (x86_64-linux-gnu)
CPU: 48 × AMD EPYC 7V13 64-Core Processor
WORD_SIZE: 64
LLVM: libLLVM-18.1.7 (ORCJIT, znver3)
GC: Built with stock GC
Threads: 1 default, 1 interactive, 1 GC (on 48 virtual cores)
julia> Pkg.status()
Status `~/temp/Project.toml`
[992eb4ea] CondaPkg v0.2.33
[6099a3de] PythonCall v0.9.28
Python Environment
- python 3.13.9
- numpy 2.3.4
I noticed a difference in how the PythonCall to_numpy() function and NumPy treat property values of dtype as follows:
julia> using PythonCall
julia> Py(rand(10)).to_numpy().dtype
Python: dtype('float64')
julia> Py([[1,2,3], [4,5,6]]).to_numpy().dtype
Python: dtype('O')
I would expect the latter to be dtype('int64') to match Python:
>>> import numpy
>>> a = numpy.array([[1,2,3], [4,5,6]])
>>> a.dtype
dtype('int64')
While Julia does provide Matrix{Int64} and to_numpy() outputs dtype('int64') as I would expect
julia> [1 2 3; 4 5 6] |> typeof
Matrix{Int64} (alias for Array{Int64, 2})
julia> Py([1 2 3; 4 5 6]).to_numpy().dtype
Python: dtype('int64')
I am working on a project where I need to use PythonCall to deal with Vector{Vector{Int64}} instances and changing into Matrix{Int64} is not an option.
In Julia, using PythonCall to_numpy(), it is clear that dtype('int64') is only output for Vector{Int64} not Vector{Vector{Int64}} nor Vector{Vector{Vector{Int64}}} regardless of how many levels of nesting:
julia> Py([1, 2, 3]).to_numpy().dtype
Python: dtype('int64')
julia> Py([[1,2,3], [4,5,6]]).to_numpy().dtype
Python: dtype('O')
julia> Py([[[1,2,3], [4,5,6]], [[7,8,9], [10,11,12]]]).to_numpy().dtype
Python: dtype('O')
Whereas in Python, dtype('int64') is output for all the above:
>>> numpy.array([1, 2, 3]).dtype
dtype('int64')
>>> numpy.array([[1,2,3], [4,5,6]]).dtype
dtype('int64')
>>> numpy.array([[[1,2,3], [4,5,6]], [[7,8,9], [10,11,12]]]).dtype
dtype('int64')
Thus the value of the property .dtype in NumPy is defined based on the innermost elements in the array, whereas in Julia the value of .dtype upon using to_numpy() is not based on the innermost elements (i.e. 1, 2, 3, etc) but on the whole structure containing them (i.e Vector{Int64} for the 2nd array, and Vector{Vector{Int64}} for the 3rd array).
I was expecting the same behaviour from Python's NumPy and the conversions from to_numpy() given by PythonCall, but it turns out the conversion does not agree with NumPy on dtype property values.
- Lingua principale
- Julia
- Stelle
- 1.1k
- Fork
- 89
- Merge medio
- 2g 15h
- PR unite (30g)
- 7
Preparare l'ambiente
Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di JuliaPy/PythonCall.jl
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 55/100
JuliaPy/PythonCall.jl#828 · 7 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
JuliaPy/PythonCall.jl#809 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Locking julia dependenciesApertaenhancement
Difficoltà 5/5 Più di una settimana Idoneità per principianti 35/100
JuliaPy/PythonCall.jl#805 · 4 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
enhancement
Difficoltà 3/5 1-2 giorni Idoneità per principianti 68/100
JuliaPy/PythonCall.jl#796 ·
I maintainer di solito rispondono entro 1 giorno
-
enhancement
Difficoltà 5/5 Più di una settimana Idoneità per principianti 25/100
JuliaPy/PythonCall.jl#790 ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di JuliaPy/PythonCall.jl
Issue simili
-
Chains resumed from `initial_state` take `num_warmup + 1` warm-up stepsForse già presa @thevolatilebit l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 80/100
TuringLang/AbstractMCMC.jl#220 ·
-
found-by-agent
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
exanauts/SparseDirectSolver.jl#92 ·
I maintainer di solito rispondono entro 1 giorno
-
`inv` of a dense matrix fails for arrays whose `parent` is not an array of the same kindForse già presa @devmotion l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
JuliaLang/LinearAlgebra.jl#1740 ·
I maintainer di solito rispondono entro 2 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 90/100
NumericalEarth/Breeze.jl#1051 ·
I maintainer di solito rispondono entro 1 giorno