JuliaPy / JuliaPy/PyCall.jl

RFC: Lazier and more interface-based conversion

Ouverte
#617 16 commentaires 10 réactions 0 personnes assignées Voir sur GitHub
Langage dominant
Julia
Étoiles
1.5k
Forks
186
Métriques de merge des PR
Aucune PR mergée en 30 j

Description

Rather than trying to convert and copy values between Python and Julia, I propose to:

1. Enhance `pyjlwrap` and implement most of [Python data model](https://docs.python.org/3/reference/datamodel.html) such that virtually all Julia values are usable with `pyjlwrap`. For example, we can translate `getindex` to `__getitem__` etc. such that we can use an `AbstractArray` without translating it to a Numpy array. We can also implement `__array__` in Julia side to make `numpy.asarray` fast.

2. Restrict automatic conversion to Julia types which supports ("practically") lossless round-trip (Julia -> Python -> Julia). Maybe something like:

```julia
Union{
Nothing,
Integer,
NpyNumber, # Int64, Float16, Float32, Float64, ...
Array{<: NpyNumber},
String,
Dates.AbstractTime, # or maybe only the concrete subtypes
IO, # ditto
}
```

Here is a reference implementation that shows this approach works: https://github.com/tkf/PyBase.jl

It would solve, e.g.,:
https://github.com/JuliaPy/PyCall.jl/issues/11
https://github.com/JuliaPy/PyCall.jl/issues/175
https://github.com/JuliaPy/PyCall.jl/issues/507
https://github.com/JuliaPy/PyCall.jl/issues/555
https://github.com/JuliaPy/PyCall.jl/issues/616
https://github.com/JuliaPy/PyPlot.jl/issues/391
https://github.com/JuliaPy/PyPlot.jl/issues/400
https://github.com/JuliaPy/pyjulia/issues/122
https://github.com/JuliaPy/pyjulia/issues/123
https://github.com/JuliaDiffEq/diffeqpy/issues/21

There are many details that can be refined (e.g., rather than using a single Python class, maybe define a few base class? Or even create Python class on-demand?) but first I'd like to know if it is a reasonable direction for PyCall.jl.

Guide de contribution

Aucun guide de contribution indexé pour ce dépôt

Piste de recherche

Start by reviewing the existing pyjlwrap approach and the linked PyBase.jl reference implementation, then compare them with the listed conversion-related issues. Done means establishing whether the proposed interface-based conversion direction is suitable for PyCall.jl and refining its scope before implementation.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
julia, python
Domaine
developer-experience, tooling
Type d'issue
Fonctionnalité
Difficulté
5/5
Temps estimé
Plus d'une semaine
Activité
À l'abandon
Clarté
Plutôt claire
Accessibilité débutants
25/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.