Skip to content

[Python] Pickling a sliced array serializes all the buffers #26685

Description

@asfimport

If a large array is sliced, and pickled, it seems the full buffer is serialized, this leads to excessive memory usage and data transfer when using multiprocessing or dask.

>>> importpyarrowaspa
>>> ar = pa.array(['foo'] * 100_000)
>>> ar.nbytes700004
>>> importpickle
>>> len(pickle.dumps(ar.slice(10, 1)))
700165NumPyforinstance
>>> importnumpyasnp
>>> ar_np = np.array(ar)
>>> ar_nparray(['foo', 'foo', 'foo', ..., 'foo', 'foo', 'foo'], dtype=object)
>>> importpickle
>>> len(pickle.dumps(ar_np[10:11]))
165

I think this makes sense if you know arrow, but kind of unexpected as a user.

Is there a workaround for this? For instance copy an arrow array to get rid of the offset, and trim the buffers?

Reporter: Maarten Breddels / @maartenbreddels
Assignee: Clark Zinzow

Related issues:

Note: This issue was originally created as ARROW-10739. Please see the migration documentation for further details.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions