Skip to content

Commit

Permalink
Subclass cuDF objects from Serializable
Browse files Browse the repository at this point in the history
  • Loading branch information
jakirkham committed May 8, 2020
1 parent df37353 commit 4b085dc
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 38 deletions.
7 changes: 3 additions & 4 deletions python/cudf/cudf/core/buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
import rmm
from rmm import DeviceBuffer, _DevicePointer

from cudf.core.abc import Serializable

class Buffer:

class Buffer(Serializable):
def __init__(self, data=None, size=None, owner=None):
"""
A Buffer represents a device memory allocation.
Expand Down Expand Up @@ -58,9 +60,6 @@ def __init__(self, data=None, size=None, owner=None):
raise TypeError("data must be Buffer, array-like or integer")
self._init_from_array_like(np.asarray(data), owner)

def __reduce__(self):
return self.__class__, (self.to_host_array(),)

def __len__(self):
return self.size

Expand Down
17 changes: 2 additions & 15 deletions python/cudf/cudf/core/column/column.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from cudf._lib.scalar import as_scalar
from cudf._lib.stream_compaction import unique_count as cpp_unique_count
from cudf._lib.transform import bools_to_mask
from cudf.core.abc import Serializable
from cudf.core.buffer import Buffer
from cudf.core.dtypes import CategoricalDtype
from cudf.utils import cudautils, ioutils, utils
Expand All @@ -38,7 +39,7 @@
from cudf.utils.utils import buffers_from_pyarrow, mask_dtype


class ColumnBase(Column):
class ColumnBase(Serializable, Column):
def __init__(
self,
data,
Expand Down Expand Up @@ -67,20 +68,6 @@ def __init__(
children=children,
)

def __reduce__(self):
return (
build_column,
(
self.data,
self.dtype,
self.mask,
self.size,
0,
self.null_count,
self.children,
),
)

def as_frame(self):
from cudf.core.frame import Frame

Expand Down
6 changes: 2 additions & 4 deletions python/cudf/cudf/core/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from cudf._lib.null_mask import MaskState, create_null_mask
from cudf._lib.nvtx import annotate
from cudf.core import column
from cudf.core.abc import Serializable
from cudf.core.column import as_column, column_empty
from cudf.core.column_accessor import ColumnAccessor
from cudf.core.frame import Frame
Expand Down Expand Up @@ -87,7 +88,7 @@ def _reverse_op(fn):
}[fn]


class DataFrame(Frame):
class DataFrame(Serializable, Frame):
"""
A GPU Dataframe object.
Expand Down Expand Up @@ -1631,9 +1632,6 @@ def __deepcopy__(self, memo={}):
memo = {}
return self.copy(deep=True)

def __reduce__(self):
return (DataFrame, (self._data, self.index))

@annotate("INSERT", color="green", domain="cudf_python")
def insert(self, loc, name, value):
""" Add a column to DataFrame at the index specified by loc.
Expand Down
5 changes: 3 additions & 2 deletions python/cudf/cudf/core/groupby/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
import pandas as pd

import cudf
from cudf.core.abc import Serializable
import cudf._lib.groupby as libgroupby
from cudf._lib.nvtx import annotate


class GroupBy(object):
class GroupBy(Serializable):
"""
Group a DataFrame or Series by a set of columns.
Expand Down Expand Up @@ -510,7 +511,7 @@ def __init__(self, key=None, level=None):
self.level = level


class _Grouping(object):
class _Grouping(Serializable):
def __init__(self, obj, by=None, level=None):
self._obj = obj
self._key_columns = []
Expand Down
13 changes: 2 additions & 11 deletions python/cudf/cudf/core/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import cudf
from cudf._lib.nvtx import annotate
from cudf.core.abc import Serializable
from cudf.core.column import (
CategoricalColumn,
ColumnBase,
Expand Down Expand Up @@ -57,7 +58,7 @@ def _to_frame(this_index, index=True, name=None):
)


class Index(Frame):
class Index(Serializable, Frame):
"""The root interface for all Series indexes.
"""

Expand Down Expand Up @@ -646,9 +647,6 @@ def __getitem__(self, index):
def __eq__(self, other):
return super(type(self), self).__eq__(other)

def __reduce__(self):
return (RangeIndex, (self._start, self._stop, self.name))

def equals(self, other):
if self is other:
return True
Expand Down Expand Up @@ -829,13 +827,6 @@ def copy(self, deep=True):
def __sizeof__(self):
return self._values.__sizeof__()

def __reduce__(self):
_maker = functools.partial(
self.__class__, self._values, name=self.name
)

return _maker, ()

def __len__(self):
return len(self._values)

Expand Down
3 changes: 2 additions & 1 deletion python/cudf/cudf/core/multiindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
import pandas as pd

import cudf
from cudf.core.abc import Serializable
from cudf.core.column import column
from cudf.core.index import Index, as_index


class MultiIndex(Index):
class MultiIndex(Serializable, Index):
"""A multi-level or hierarchical index.
Provides N-Dimensional indexing into Series and DataFrame objects.
Expand Down
3 changes: 2 additions & 1 deletion python/cudf/cudf/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import cudf
import cudf._lib as libcudf
from cudf._lib.nvtx import annotate
from cudf.core.abc import Serializable
from cudf.core.column import (
ColumnBase,
DatetimeColumn,
Expand All @@ -34,7 +35,7 @@
)


class Series(Frame):
class Series(Serializable, Frame):
"""
Data and null-masks.
Expand Down

0 comments on commit 4b085dc

Please sign in to comment.