Skip to content

Fix tokenize with empty attrs #8101

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 5 commits into from
Sep 9, 2023
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
2 changes: 2 additions & 0 deletions doc/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ Deprecations
Bug fixes
~~~~~~~~~

- Fix bug where empty attrs would generate inconsistent tokens (:issue:`6970`, :pull:`8101`).
By `Mattia Almansi <https://github.com/malmans2>`_.
- Improved handling of multi-coordinate indexes when updating coordinates, including bug fixes
(and improved warnings for deprecated features) for pandas multi-indexes (:pull:`8094`).
By `Benoît Bovy <https://github.com/benbovy>`_.
Expand Down
2 changes: 1 addition & 1 deletion xarray/core/variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ def __dask_tokenize__(self):
# around NetCDF and the like
from dask.base import normalize_token

return normalize_token((type(self), self._dims, self.data, self._attrs))
return normalize_token((type(self), self._dims, self.data, self.attrs))

def __dask_graph__(self):
if is_duck_dask_array(self._data):
Expand Down
11 changes: 11 additions & 0 deletions xarray/tests/test_dask.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,17 @@ def test_persist(self):
self.assertLazyAndAllClose(u + 1, v)
self.assertLazyAndAllClose(u + 1, v2)

def test_tokenize_empty_attrs(self) -> None:
# Issue #6970
assert self.eager_var._attrs is None
expected = dask.base.tokenize(self.eager_var)
assert self.eager_var.attrs == self.eager_var._attrs == {}
assert (
expected
== dask.base.tokenize(self.eager_var)
== dask.base.tokenize(self.lazy_var.compute())
)

@requires_pint
def test_tokenize_duck_dask_array(self):
import pint
Expand Down