Skip to content

Commit

Permalink
Update dask make_meta changes to be compatible with dask upstream (#8426
Browse files Browse the repository at this point in the history
)

This PR updates the `make_meta` dispatch renaming to be compatible and back-ward compatible with latest dask and older versions of dask respectively.

This PR needs upstream dask changes: dask/dask#7743

Authors:
  - GALI PREM SAGAR (https://github.com/galipremsagar)

Approvers:
  - https://github.com/jakirkham

URL: #8426
  • Loading branch information
galipremsagar authored Jun 4, 2021
1 parent 0712ffa commit 37cdc71
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 19 deletions.
14 changes: 10 additions & 4 deletions python/dask_cudf/dask_cudf/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,20 @@
_scalar_from_dtype,
is_arraylike,
is_scalar,
make_meta,
)

try:
from dask.dataframe.utils import make_meta_obj as make_meta_obj
except ImportError:
from dask.dataframe.utils import make_meta as make_meta_obj

try:
from dask.dataframe.dispatch import (
make_meta_dispatch as make_meta_dispatch,
)
except ImportError:
from dask.dataframe.utils import make_meta as make_meta_dispatch

import cudf
from cudf.utils.dtypes import is_string_dtype

Expand Down Expand Up @@ -121,12 +127,12 @@ def meta_nonempty_cudf(x):
return res


@make_meta.register((cudf.Series, cudf.DataFrame))
@make_meta_dispatch.register((cudf.Series, cudf.DataFrame))
def make_meta_cudf(x, index=None):
return x.head(0)


@make_meta.register(cudf.Index)
@make_meta_dispatch.register(cudf.Index)
def make_meta_cudf_index(x, index=None):
return x[:0]

Expand Down Expand Up @@ -173,7 +179,7 @@ def make_meta_object_cudf(x, index=None):
return x[:0]

if index is not None:
index = make_meta(index)
index = make_meta_dispatch(index)

if isinstance(x, dict):
return cudf.DataFrame(
Expand Down
13 changes: 7 additions & 6 deletions python/dask_cudf/dask_cudf/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@
from dask.compatibility import apply
from dask.context import _globals
from dask.core import flatten
from dask.dataframe.core import Scalar, finalize, handle_out, map_partitions
from dask.dataframe.core import (
Scalar,
finalize,
handle_out,
make_meta as dask_make_meta,
map_partitions,
)
from dask.dataframe.utils import raise_on_meta_error
from dask.highlevelgraph import HighLevelGraph
from dask.optimization import cull, fuse
Expand All @@ -26,11 +32,6 @@
from dask_cudf import sorting
from dask_cudf.accessors import ListMethods

try:
from dask.dataframe.utils import make_meta_util as dask_make_meta
except ImportError:
from dask.dataframe.core import make_meta as dask_make_meta

DASK_VERSION = LooseVersion(dask.__version__)


Expand Down
12 changes: 3 additions & 9 deletions python/dask_cudf/dask_cudf/tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,7 @@

import dask
from dask import dataframe as dd
from dask.dataframe.core import meta_nonempty

try:
from dask.dataframe.utils import make_meta_util as dask_make_meta
except ImportError:
from dask.dataframe.core import make_meta as dask_make_meta

from dask.dataframe.core import make_meta as dask_make_meta, meta_nonempty
from dask.utils import M

import cudf
Expand Down Expand Up @@ -827,9 +821,9 @@ def test_merging_categorical_columns():

def test_correct_meta():
try:
from dask.dataframe.utils import make_meta_util # noqa: F401
from dask.dataframe.dispatch import make_meta_obj # noqa: F401
except ImportError:
pytest.skip("need make_meta_util to be preset")
pytest.skip("need make_meta_obj to be preset")

# Need these local imports in this specific order.
# For context: https://github.com/rapidsai/cudf/issues/7946
Expand Down

0 comments on commit 37cdc71

Please sign in to comment.