Skip to content

Commit aca2701

Browse files
author
Christopher Doris
committed
document JULIA_PYTHONCALL_PICKLE
1 parent f898a2c commit aca2701

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

docs/src/compat.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ functions to bridge a gap. We aim to keep these as minimal as possible.
99

1010
Whenever a Python exception is displayed by Julia, `sys.last_traceback` and friends are set. This allows the post-mortem debugger `pdb.pm()` to work. Disable by setting `PythonCall.CONFIG.auto_sys_last_traceback = false`.
1111

12+
## Julia standard library
13+
14+
Python objects can be serialised with the [`Serialization`](https://docs.julialang.org/en/v1/stdlib/Serialization/) stdlib.
15+
This uses [`pickle`](https://docs.python.org/3/library/pickle.html) library under the hood.
16+
You can opt into using [`dill`](https://pypi.org/project/dill/) instead by setting the environment variable `JULIA_PYTHONCALL_PICKLE="dill"`.
17+
1218
## Tabular data / Pandas
1319

1420
The abstract type [`PyTable`](@ref) is for wrapper types around Python tables, providing the

docs/src/releasenotes.md

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

3+
## Unreleased
4+
* `Serialization.serialize` can use `dill` instead of `pickle` by setting the env var `JULIA_PYTHONCALL_PICKLE=dill`.
5+
36
## 0.9.20 (2024-05-01)
47
* The IPython extension is now automatically loaded upon import if IPython is detected.
58
* JuliaCall now compatible with Julia 1.10.3.

src/Compat/serialization.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
#
33
# We use pickle to serialise Python objects to bytes.
44

5+
_pickle_module() = pyimport(get(ENV, "JULIA_PYTHONCALL_PICKLE", "pickle"))
6+
57
function serialize_py(s, x::Py)
68
if pyisnull(x)
79
serialize(s, nothing)
810
else
9-
b = pyimport(get(ENV, "JULIA_PYTHONCALL_PICKLE", "pickle")).dumps(x)
11+
b = _pickle_module().dumps(x)
1012
serialize(s, pybytes_asvector(b))
1113
end
1214
end
@@ -16,7 +18,7 @@ function deserialize_py(s)
1618
if v === nothing
1719
pynew()
1820
else
19-
pyimport(get(ENV, "JULIA_PYTHONCALL_PICKLE", "pickle")).loads(pybytes(v))
21+
_pickle_module().loads(pybytes(v))
2022
end
2123
end
2224

0 commit comments

Comments
 (0)