Skip to content

Commit

Permalink
document JULIA_PYTHONCALL_PICKLE
Browse files Browse the repository at this point in the history
  • Loading branch information
Christopher Doris committed May 12, 2024
1 parent f898a2c commit aca2701
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
6 changes: 6 additions & 0 deletions docs/src/compat.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ functions to bridge a gap. We aim to keep these as minimal as possible.

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`.

## Julia standard library

Python objects can be serialised with the [`Serialization`](https://docs.julialang.org/en/v1/stdlib/Serialization/) stdlib.
This uses [`pickle`](https://docs.python.org/3/library/pickle.html) library under the hood.
You can opt into using [`dill`](https://pypi.org/project/dill/) instead by setting the environment variable `JULIA_PYTHONCALL_PICKLE="dill"`.

## Tabular data / Pandas

The abstract type [`PyTable`](@ref) is for wrapper types around Python tables, providing the
Expand Down
3 changes: 3 additions & 0 deletions docs/src/releasenotes.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Release Notes

## Unreleased
* `Serialization.serialize` can use `dill` instead of `pickle` by setting the env var `JULIA_PYTHONCALL_PICKLE=dill`.

## 0.9.20 (2024-05-01)
* The IPython extension is now automatically loaded upon import if IPython is detected.
* JuliaCall now compatible with Julia 1.10.3.
Expand Down
6 changes: 4 additions & 2 deletions src/Compat/serialization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
#
# We use pickle to serialise Python objects to bytes.

_pickle_module() = pyimport(get(ENV, "JULIA_PYTHONCALL_PICKLE", "pickle"))

function serialize_py(s, x::Py)
if pyisnull(x)
serialize(s, nothing)
else
b = pyimport(get(ENV, "JULIA_PYTHONCALL_PICKLE", "pickle")).dumps(x)
b = _pickle_module().dumps(x)
serialize(s, pybytes_asvector(b))
end
end
Expand All @@ -16,7 +18,7 @@ function deserialize_py(s)
if v === nothing
pynew()
else
pyimport(get(ENV, "JULIA_PYTHONCALL_PICKLE", "pickle")).loads(pybytes(v))
_pickle_module().loads(pybytes(v))
end
end

Expand Down

0 comments on commit aca2701

Please sign in to comment.