Skip to content

Commit c16d0db

Browse files
committed
WIP
1 parent 5f05058 commit c16d0db

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

xarray/core/dataset.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,17 @@ def _get_breaks_cached(
316316
return None
317317

318318

319+
_STR_CACHE = dict()
320+
321+
322+
def cached_str(chunks: tuple[int, ...]) -> str:
323+
if id(chunks) not in _STR_CACHE:
324+
value = str(chunks)
325+
_STR_CACHE[id(chunks)] = value
326+
327+
return _STR_CACHE[id(chunks)]
328+
329+
319330
def _maybe_chunk(
320331
name: Hashable,
321332
var: Variable,
@@ -344,7 +355,13 @@ def _maybe_chunk(
344355
# by providing chunks as an input to tokenize.
345356
# subtle bugs result otherwise. see GH3350
346357
# we use str() for speed, and use the name for the final array name on the next line
347-
token2 = tokenize(token if token else var._data, str(chunks))
358+
token2 = tokenize(
359+
token if token else var._data,
360+
[
361+
cached_str(_)
362+
for _ in itertools.chain(chunks.keys(), chunks.values())
363+
],
364+
)
348365
name2 = f"{name_prefix}{name}-{token2}"
349366

350367
from_array_kwargs = utils.consolidate_dask_from_array_kwargs(

0 commit comments

Comments
 (0)