Skip to content

Support HighLevelGraphs #2603

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

Merged
merged 4 commits into from
Dec 13, 2018
Merged
Show file tree
Hide file tree
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
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ matrix:
- libhdf5-serial-dev
- netcdf-bin
- libnetcdf-dev
- env: CONDA_ENV=py36-dask-dev
- env: CONDA_ENV=py36-pandas-dev
- env: CONDA_ENV=py36-bottleneck-dev
- env: CONDA_ENV=py36-condaforge-rc
Expand Down
7 changes: 4 additions & 3 deletions doc/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ Enhancements
By `Stephan Hoyer <https://github.com/shoyer>`_
- Like :py:class:`pandas.DatetimeIndex`, :py:class:`CFTimeIndex` now supports
"dayofyear" and "dayofweek" accessors (:issue:`2597`). By `Spencer Clark
<https://github.com/spencerkclark>`_.
<https://github.com/spencerkclark>`_.
- Support Dask ``HighLevelGraphs`` by `Matthew Rocklin <https://matthewrocklin.com>`_.


Bug fixes
Expand Down Expand Up @@ -159,9 +160,9 @@ Enhancements
to returning (and is now deprecated). This was changed in order to facilitate
using tutorial datasets with dask.
By `Joe Hamman <https://github.com/jhamman>`_.
- ``DataArray`` can now use ``xr.set_option(keep_attrs=True)`` and retain attributes in binary operations,
- ``DataArray`` can now use ``xr.set_option(keep_attrs=True)`` and retain attributes in binary operations,
such as (``+, -, * ,/``). Default behaviour is unchanged (*Attributes will be dismissed*). By `Michael Blaschek <https://github.com/MBlaschek>`_

Bug fixes
~~~~~~~~~

Expand Down
3 changes: 3 additions & 0 deletions xarray/core/dataarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,9 @@ def __dask_graph__(self):
def __dask_keys__(self):
return self._to_temp_dataset().__dask_keys__()

def __dask_layers__(self):
return self._to_temp_dataset().__dask_layers__()

@property
def __dask_optimize__(self):
return self._to_temp_dataset().__dask_optimize__
Expand Down
14 changes: 12 additions & 2 deletions xarray/core/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,14 +509,24 @@ def __dask_graph__(self):
if not graphs:
return None
else:
from dask import sharedict
return sharedict.merge(*graphs.values())
try:
from dask.highlevelgraph import HighLevelGraph
return HighLevelGraph.merge(*graphs.values())
except ImportError:
from dask import sharedict
return sharedict.merge(*graphs.values())


def __dask_keys__(self):
import dask
return [v.__dask_keys__() for v in self.variables.values()
if dask.is_dask_collection(v)]

def __dask_layers__(self):
import dask
return sum([v.__dask_layers__() for v in self.variables.values() if
dask.is_dask_collection(v)], ())

@property
def __dask_optimize__(self):
import dask.array as da
Expand Down
3 changes: 3 additions & 0 deletions xarray/core/variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,9 @@ def __dask_graph__(self):
def __dask_keys__(self):
return self._data.__dask_keys__()

def __dask_layers__(self):
return self._data.__dask_layers__()

@property
def __dask_optimize__(self):
return self._data.__dask_optimize__
Expand Down
13 changes: 13 additions & 0 deletions xarray/tests/test_dask.py
Original file line number Diff line number Diff line change
Expand Up @@ -843,3 +843,16 @@ def test_basic_compute():
ds.compute()
ds.foo.compute()
ds.foo.variable.compute()


@pytest.mark.skipif(LooseVersion(dask.__version__) < LooseVersion('0.20.0'),
reason='needs newer dask')
def test_dask_layers_and_dependencies():
ds = Dataset({'foo': ('x', range(5)),
'bar': ('x', range(5))}).chunk()

x = dask.delayed(ds)
assert set(x.__dask_graph__().dependencies).issuperset(
ds.__dask_graph__().dependencies)
assert set(x.foo.__dask_graph__().dependencies).issuperset(
ds.__dask_graph__().dependencies)