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 support for pylibcudf.DataType serialization #17352

Merged
merged 10 commits into from
Nov 28, 2024
28 changes: 28 additions & 0 deletions python/pylibcudf/pylibcudf/tests/test_serialize.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Copyright (c) 2024, NVIDIA CORPORATION.
import pickle

import pytest

from pylibcudf import DataType
from pylibcudf.types import TypeId


@pytest.fixture(params=list(TypeId))
def dtype(request):
tid = request.param
if tid in {TypeId.DECIMAL32, TypeId.DECIMAL64, TypeId.DECIMAL128}:
scale = 5
else:
scale = 0
return DataType(tid, scale)


def test_reduce(dtype):
(typ, (tid, scale)) = dtype.__reduce__()
assert typ is DataType
assert tid == dtype.id()
assert scale == dtype.scale()


def test_pickle(dtype):
assert dtype == pickle.loads(pickle.dumps(dtype))
3 changes: 3 additions & 0 deletions python/pylibcudf/pylibcudf/types.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ cdef class DataType:
def __hash__(self):
return hash((self.c_obj.id(), self.c_obj.scale()))

def __reduce__(self):
return (type(self), (self.c_obj.id(), self.c_obj.scale()))

@staticmethod
cdef DataType from_libcudf(data_type dt):
"""Create a DataType from a libcudf data_type.
Expand Down
Loading