PyCall giving Ptr instead of PyObject


I’m trying to load a python file that was pickled using joblib. The file is a python dict that contains several objects, including a few DataFrames. When I load the dict in Python it’s fine, but when I try to load it through PyCall the DataFrames turn into pointers like PyObject Ptr{PyCall.PyObject_struct} @0x00007f124438c3d0

Example code:

using PyCall
joblib = pyimport("joblib")
output_dict = joblib.load("myfile.pickle")


Dict{Any,Any} with 6 entries:
  "array1" => [3.84204, 3.90863, 3.91936, 4.1192, 4.13436, 4.14225…
  "array2"        => Any["b544ea00d3efc43c18d34c5cbd58882340016f6c" PyObj…
  "int"          => 14
  "df1"       => PyObject Ptr{PyCall.PyObject_struct} @0x00007f124438…
  "df2"                  => PyObject Ptr{PyCall.PyObject_struct} @0x00007f12444e…
  "df3"     => PyObject Ptr{PyCall.PyObject_struct} @0x00007f124433…

Is there a way to recover the Python object from these pointers?

I attempted to create an MWE, but couldn’t reproduce the issue – saving and loading a dataframe worked correctly.

Python objects are stored as pointers. Normally, however, PyCall displays an object via the Python repr of that object, and only shows the raw pointer when repr throws an exception.

To see what exception is preventing the repr from being displayed, try calling pyrepr(output_dict["df1"]).


Thanks! It turns out I built my PyCall with the wrong environment, which had led it to use an older version of pandas, which throws an exception when you try to view a dataframe from a newer version.

1 Like