Skip to content

Commit 89a6349

Browse files
authored
Add a fast path that doesn't include normalized chunks in tokenize (#11017)
1 parent d68c013 commit 89a6349

2 files changed

Lines changed: 12 additions & 8 deletions

File tree

xarray/backends/api.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ def _chunk_ds(
265265
inline_array=inline_array,
266266
chunked_array_type=chunkmanager,
267267
from_array_kwargs=from_array_kwargs.copy(),
268+
just_use_token=True,
268269
)
269270
return backend_ds._replace(variables)
270271

xarray/structure/chunks.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ def _maybe_chunk(
7272
inline_array: bool = False,
7373
chunked_array_type: str | ChunkManagerEntrypoint | None = None,
7474
from_array_kwargs=None,
75+
just_use_token=False,
7576
) -> Variable:
7677
from xarray.namedarray.daskmanager import DaskManager
7778

@@ -83,14 +84,16 @@ def _maybe_chunk(
8384
chunked_array_type
8485
) # coerce string to ChunkManagerEntrypoint type
8586
if isinstance(chunked_array_type, DaskManager):
86-
from dask.base import tokenize
87-
88-
# when rechunking by different amounts, make sure dask names change
89-
# by providing chunks as an input to tokenize.
90-
# subtle bugs result otherwise. see GH3350
91-
# we use str() for speed, and use the name for the final array name on the next line
92-
token2 = tokenize(token or var._data, str(chunks))
93-
name2 = f"{name_prefix}{name}-{token2}"
87+
if not just_use_token:
88+
from dask.base import tokenize
89+
90+
# when rechunking by different amounts, make sure dask names change
91+
# by providing chunks as an input to tokenize.
92+
# subtle bugs result otherwise. see GH3350
93+
# we use str() for speed, and use the name for the final array name on the next line
94+
token = tokenize(token or var._data, str(chunks))
95+
96+
name2 = f"{name_prefix}{name}-{token}"
9497

9598
from_array_kwargs = utils.consolidate_dask_from_array_kwargs(
9699
from_array_kwargs,

0 commit comments

Comments
 (0)