Skip to content
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

Implement deterministic hashing as part of Dask collection interface #1151

Merged
merged 1 commit into from
Aug 19, 2020
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
5 changes: 4 additions & 1 deletion pint/quantity.py
Original file line number Diff line number Diff line change
Expand Up @@ -1964,6 +1964,9 @@ def __dask_graph__(self):
def __dask_keys__(self):
return self._magnitude.__dask_keys__()

def __dask_tokenize__(self):
return (Quantity, self._magnitude.name, self.units)

@property
def __dask_optimize__(self):
return dask_array.Array.__dask_optimize__
Expand Down Expand Up @@ -2028,7 +2031,7 @@ def visualize(self, **kwargs):
Parameters
----------
**kwargs : dict
Any keyword arguments to pass to the ``dask.base.visualize`` function.
Any keyword arguments to pass to ``dask.visualize``.

Returns
-------
Expand Down
9 changes: 9 additions & 0 deletions pint/testsuite/test_dask.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,15 @@ def test_dask_scheduler(dask_array):
assert scheduler_name == true_name


def test_dask_tokenize(dask_array):
"""Test that a pint.Quantity wrapped Dask array has a unique token."""
dask_token = dask.base.tokenize(dask_array)
q = ureg.Quantity(dask_array, units_)

assert dask.base.tokenize(dask_array) != dask.base.tokenize(q)
assert dask.base.tokenize(dask_array) == dask_token


def test_dask_optimize(dask_array):
"""Test that a pint.Quantity wrapped Dask array can be optimized."""
q = ureg.Quantity(dask_array, units_)
Expand Down