Skip to content

Commit

Permalink
Add Buffer "constructor-kwargs" header
Browse files Browse the repository at this point in the history
Part of `Buffer`'s serializers' work includes handling subclasses (like
cuML's `Array`). However it doesn't handle any keyword arguments those
subclass constructors may need. This changes that by adding an optional
(by default trivial) "constructor-kwargs" header. Subclasses can then
call their parents' serializer and pack this header with relevant
content afterwards. This way during deserialization this content can be
passed into the subclass' constructor.
  • Loading branch information
jakirkham committed Feb 15, 2020
1 parent 6fe4c47 commit 61fe635
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
- PR #4053 Multi-column quantiles.
- PR #4107 Add groupby nunique aggregation
- PR #4153 Support Dask serialization protocol on cuDF objects
- PR #4164 Add Buffer "constructor-kwargs" header

## Improvements

Expand Down
3 changes: 2 additions & 1 deletion python/cudf/cudf/core/buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,14 @@ def _init_from_array_like(self, data):
def serialize(self):
header = {}
header["type-serialized"] = pickle.dumps(type(self))
header["constructor-kwargs"] = {}
header["desc"] = self.__cuda_array_interface__.copy()
frames = [self]
return header, frames

@classmethod
def deserialize(cls, header, frames):
buf = cls(frames[0])
buf = cls(frames[0], **header["constructor-kwargs"])

if header["desc"]["shape"] != buf.__cuda_array_interface__["shape"]:
raise ValueError(
Expand Down

0 comments on commit 61fe635

Please sign in to comment.