Skip to content

Commit

Permalink
Support kwargs in tokenize
Browse files Browse the repository at this point in the history
  • Loading branch information
mrocklin committed Oct 27, 2015
1 parent a237000 commit 9775c38
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 3 additions & 1 deletion dask/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def normalize_array(x):
return (data, x.dtype, x.shape, x.strides)


def tokenize(*args):
def tokenize(*args, **kwargs):
""" Deterministic token
>>> tokenize([1, 2, '3'])
Expand All @@ -190,4 +190,6 @@ def tokenize(*args):
>>> tokenize('Hello') == tokenize('Hello')
True
"""
if kwargs:
args = args + (kwargs,)
return md5(str(tuple(map(normalize_token, args))).encode()).hexdigest()
6 changes: 6 additions & 0 deletions dask/tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ def test_tokenize_pandas():
assert tokenize(a) == tokenize(b)


def test_tokenize_kwargs():
assert tokenize(5, x=1) == tokenize(5, x=1)
assert tokenize(5) != tokenize(5, x=1)
assert tokenize(5, x=1) != tokenize(5, x=2)
assert tokenize(5, x=1) != tokenize(5, y=1)

da = pytest.importorskip('dask.array')
import numpy as np

Expand Down

0 comments on commit 9775c38

Please sign in to comment.