Skip to content

Commit

Permalink
Allow tuples as sharedict keys
Browse files Browse the repository at this point in the history
  • Loading branch information
mrocklin committed Oct 11, 2017
1 parent 3270bee commit 16da57b
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion dask/array/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def _check_dsk(dsk):
if not isinstance(dsk, ShareDict):
return

assert all(isinstance(k, str) for k in dsk.dicts)
assert all(isinstance(k, (tuple, str)) for k in dsk.dicts)
freqs = frequencies(concat(dsk.dicts.values()))
non_one = {k: v for k, v in freqs.items() if v != 1}
assert not non_one, non_one
Expand Down
2 changes: 1 addition & 1 deletion dask/delayed.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ def call_function(func, func_token, args, kwargs, pure=None, nout=None):
for arg, d in args_dasks:
if isinstance(d, sharedict.ShareDict):
dsk.update_with_key(d)
elif isinstance(arg, str):
elif isinstance(arg, (str, tuple)):
dsk.update_with_key(d, key=arg)
else:
dsk.update(d)
Expand Down
14 changes: 13 additions & 1 deletion dask/tests/test_delayed.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from dask import set_options, compute
from dask.compatibility import PY2, PY3
from dask.delayed import delayed, to_task_dask, Delayed
from dask.utils_test import inc


def test_to_task_dask():
Expand Down Expand Up @@ -442,7 +443,8 @@ def myfunc(x):


def test_finalize_name():
import dask.array as da
da = pytest.importorskip('dask.array')

x = da.ones(10, chunks=5)
v = delayed([x])
assert set(x.dask).issubset(v.dask)
Expand All @@ -453,3 +455,13 @@ def key(s):
return s.split('-')[0]

assert all(key(k).isalpha() for k in v.dask)


def test_keys_from_array():
da = pytest.importorskip('dask.array')
from dask.array.utils import _check_dsk

X = da.ones((10, 10), chunks=5).to_delayed().flatten()
xs = [delayed(inc)(x) for x in X]

_check_dsk(xs[0].dask)
2 changes: 1 addition & 1 deletion docs/source/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Bag
Core
++++

-
- Allow tuples as sharedict keys

0.15.4 / 2017-10-06
-------------------
Expand Down

0 comments on commit 16da57b

Please sign in to comment.