Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add packed serialization option for dataframes #8661

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions python/cudf/cudf/core/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import inspect
import itertools
import numbers
import os
import pickle
import sys
import warnings
Expand All @@ -24,6 +25,7 @@

import cudf
from cudf import _lib as libcudf
from cudf._lib.copying import PackedColumns, pack, unpack
from cudf._lib.null_mask import MaskState, create_null_mask
from cudf.api.types import is_bool_dtype, is_dict_like
from cudf.core import column, reshape
Expand Down Expand Up @@ -101,6 +103,9 @@
}


PACKED_SERIALIZATION = os.environ.get("CUDF_PACKED_SERIALIZATION", False)


class DataFrame(Frame, Serializable, GetAttrGetItemMixin):

_PROTECTED_KEYS = frozenset(("_data", "_index"))
Expand Down Expand Up @@ -561,6 +566,9 @@ def _constructor_expanddim(self):
)

def serialize(self):
if PACKED_SERIALIZATION:
return pack(self).serialize()

header = {}
frames = []
header["type-serialized"] = pickle.dumps(type(self))
Expand All @@ -579,6 +587,11 @@ def serialize(self):

@classmethod
def deserialize(cls, header, frames):
if PACKED_SERIALIZATION:
return cls._from_table(
unpack(PackedColumns.deserialize(header, frames))
)

# Reconstruct the index
index_frames = frames[: header["index_frame_count"]]

Expand Down