Skip to content

Commit a88f986

Browse files
author
Christopher Doris
committed
add a migration guide for v1
1 parent 4b812e3 commit a88f986

File tree

2 files changed

+83
-5
lines changed

2 files changed

+83
-5
lines changed

docs/src/releasenotes.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
# Release Notes
22

33
## Unreleased (v1)
4-
* Breaking changes to `PythonCall.GC`, which is now more like `Base.GC`:
4+
* The vast majority of these changes are breaking, see the [Migration Guide](@ref v1-migration-guide) for how to upgrade to v1.
5+
* Changes to core functionality:
6+
* Comparisons like `==(::Py, ::Py)`, `<(::Py, ::Number)`, `isless(::Number, ::Py)` now return `Bool` instead of `Py`.
7+
* Changes to `PythonCall.GC` (now more like `Base.GC`):
58
* `enable(true)` replaces `enable()`.
69
* `enable(false)` replaces `disable()`.
710
* `gc()` added.
8-
* Breaking changes to Julia wrapper types:
11+
* Changes to Julia wrapper types:
912
* Classes renamed: `ValueBase` to `JlBase`, `AnyValue` to `Jl`, `ArrayValue` to `JlArray`, etc.
1013
* Classes removed: `RawValue`, `ModuleValue`, `TypeValue`, `NumberValue`, `ComplexValue`, `RealValue`, `RationalValue`, `IntegerValue`.
1114
* `Jl` now behaves similar to how `RawValue` behaved before. In particular, most methods on `Jl` now return a `Jl` instead of an arbitrary Python object.
@@ -15,9 +18,7 @@
1518
* Methods removed: `_jl_raw()`.
1619
* `pyjl(x)` now always returns a `juliacall.Jl` (it used to select a wrapper type if possible).
1720
* `pyjltype(x)` removed.
18-
* Other breaking changes:
19-
* Comparisons like `==(::Py, ::Py)`, `<(::Py, ::Number)`, `isless(::Number, ::Py)` now return `Bool` instead of `Py`.
20-
* New functions: `pyjlarray`, `pyjldict`, `pyjlset`.
21+
* New functions: `pyjlarray`, `pyjldict`, `pyjlset`.
2122

2223
## Unreleased
2324
* Minimum supported Python version is now 3.10.

docs/src/v1-migration-guide.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# [v0.9 to v1 Migration Guide](@id v1-migration-guide)
2+
3+
## Core functionality
4+
5+
Comparisons (`==`, `<`, etc.) between Python objects `Py`, or between `Py` and `Number`,
6+
used to return `Py` but now return `Bool`. The old behaviour was a pun but broke the
7+
Base API behaviour of these functions. These comparisons will now raise an error if the
8+
underlying Python operation does not return `bool`.
9+
10+
* Instead of `pytruth(Py(3) < Py(5))` use `Py(3) < Py(5)`.
11+
* Instead of `Py(3) < Py(5)` use `Py(Py(3) < Py(5))`.
12+
* Instead of `np.array([1,2,3]) < Py(3)` use `pylt(np.array([1,2,3]), Py(3))`. This is
13+
because comparisons on numpy arrays return arrays of `bool` rather than a single
14+
`bool`.
15+
* Instead of `pylt(Bool, Py(3), Py(5))` you can use `Py(3) < Py(5)`.
16+
17+
## `PythonCall.GC`
18+
19+
This submodule has been changed to closer mimic the `Base.GC` API.
20+
21+
* Instead of `PythonCall.GC.enable()` use `PythonCall.GC.enable(true)`.
22+
* Instead of `PythonCall.GC.disable()` use `PythonCall.GC.enable(false)`.
23+
24+
## Julia wrappers (JlDict, etc.)
25+
26+
The wrapper types have been renamed.
27+
28+
* Instead of `juliacall.AnyValue` use `juliacall.Jl` (but see below).
29+
* Instead of `juliacall.ArrayValue` use `juliacall.JlArray`.
30+
* Instead of `juliacall.DictValue` use `juliacall.JlDict`.
31+
32+
Most methods on the `Jl` class return a `Jl` now instead of an arbitrary Python object
33+
converted from the Julia return value. This makes generic programming easier and
34+
more closely reflects the behaviour of `Py`.
35+
36+
* Instead of `jl.seval("1+2")` use `jl.jl_eval("1+2").jl_to_py()`.
37+
* Instead of `jl.rand(5)[0]` use `jl.rand(5)[1].jl_to_py()`. Note the shift from 0-based
38+
to 1-based indexing - previously `jl.rand(5)` was a `juliacall.VectorValue` which
39+
supported Python 0-based indexing, but now `jl.rand(5)` is a `juliacall.Jl` which
40+
supports indexing by passing the arguments directly to Julia, which is 1-based.
41+
42+
Some wrapper types have been removed and can mostly be replaced with `Jl`.
43+
44+
* Instead of `juliacall.RawValue` use `juliacall.Jl`, since this behaves much the same
45+
now.
46+
* Instead of `juliacall.IntegerValue` (and other number types) use `int`, `float`,
47+
`complex` or other numeric types as appropriate. Alternatively use `juliacall.Jl`
48+
which supports the basic arithmetic and comparison operators, but is not strictly a
49+
number.
50+
* Instead of `juliacall.ModuleValue` use `juliacall.Jl`. The only benefit of
51+
`ModuleValue` was its `seval` method, which is now `Jl.jl_eval`.
52+
* Instead of `juliacall.TypeValue` use `juliacall.Jl`. The only benefit of `TypeValue`
53+
was that indexing syntax (`jl.Vector[jl.Type]`) was converted to Julia's curly syntax
54+
(`Vector{Type}`) but `Jl` does this now (for types).
55+
56+
Methods with the `_jl_` prefix are renamed with the `jl_` prefix:
57+
* Instead of `x._jl_help()` use `x.jl_help()`.
58+
* Instead of `x._jl_display()` use `x.jl_display()`.
59+
60+
The `seval` function is now called `jl_eval`:
61+
* Instead of `juliacall.Main.seval("1+2")` use `juliacall.Main.jl_eval("1+2")`.
62+
63+
Other methods, functions and attributes removed:
64+
* Instead of `x._jl_raw()` use `x` (if already a `Jl`) or `Jl(x)`. This is because the
65+
old `AnyValue` and `RawValue` are replaced by `Jl`.
66+
* Instead of `juliacall.convert(type, value)` use `juliacall.Jl(value, type)`.
67+
* Instead of `juliacall.Pkg` you must import import it yourself, such as
68+
`juliacall.Main.jl_eval("using Pkg; Pkg")`.
69+
70+
On the Julia side, the `pyjl` function now always returns a `Jl`, whereas before it
71+
would return one of the more specific wrappers (now called `JlDict`, `JlArray`, etc.).
72+
73+
* Instead of `pyjl([1, 2, 3])` use `pyjlarray([1, 2, 3])` if you need a `JlArray`.
74+
* Instead of `pyjl(Dict())` use `pyjldict(Dict())` if you need a `JlDict`.
75+
* Instead of `pyjl(Set())` use `pyjlset(Set())` if you need a `JlSet`.
76+
* Continue to use `pyjl` if you are OK with the result being a `Jl`.
77+
* Note that `Py([1, 2, 3])` still returns a `JlArray`, etc., only `pyjl` itself changed.

0 commit comments

Comments
 (0)