JuliaPy / JuliaPy/PythonCall.jl

Working with type instabilities, coming from PyJulia

Offen
#441 4 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
Julia
Sterne
1.1k
Forks
86
Ø Merge
1 T. 22 Std.
Gemergte PRs (30 T.)
3

Beschreibung

@cjdoris Is there an automatic way to force type conversions when passing Python objects to methods? Or, in other words, is there a way to automatically convert Python arguments to their Julia counterparts?

For example I am running into this issue right now when I pass a list of integers:

```python
>>> from juliacall import Main as jl
>>> jl.seval("f(x) = (@show typeof(x); nothing)")
Julia: f (generic function with 1 method)
>>> jl.f([1, 2, 3])
typeof(x) = PyList{Any}
```

which causes some issues as now `f` is unaware of the element type of this vector.

However, in PyJulia, arguments seem to somehow get converted automatically:

```python
>>> from julia import Main as jl
>>> jl.eval("f(x) = (@show typeof(x); nothing)")

>>> jl.f([1, 2, 3])
typeof(x) = Vector{Int64}
```

Is there a way to get this same behavior in PythonCall?

---

Possibly related to #439

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.