Skip to content

Commit 20934cd

Browse files
committed
Move preserve_chunks call out of normalize_chunks
1 parent a468c4b commit 20934cd

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

xarray/namedarray/daskmanager.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,18 +55,6 @@ def normalize_chunks(
5555
"""Called by open_dataset"""
5656
from dask.array.core import normalize_chunks
5757

58-
if any(c == "preserve" for c in chunks) and any(c == "auto" for c in chunks):
59-
raise ValueError('chunks cannot use a combination of "auto" and "preserve"')
60-
61-
if shape and previous_chunks and any(c == "preserve" for c in chunks):
62-
chunks = self.preserve_chunks(
63-
chunks,
64-
shape=shape,
65-
target=self.get_auto_chunk_size(),
66-
typesize=getattr(dtype, "itemsize", 8),
67-
previous_chunks=previous_chunks,
68-
)
69-
7058
return normalize_chunks(
7159
chunks,
7260
shape=shape,

xarray/namedarray/utils.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,20 @@ def _get_chunk( # type: ignore[no-untyped-def]
236236
limit = None
237237
dtype = data.dtype
238238

239+
if any(c == "preserve" for c in chunk_shape) and any(
240+
c == "auto" for c in chunk_shape
241+
):
242+
raise ValueError('chunks cannot use a combination of "auto" and "preserve"')
243+
244+
if shape and preferred_chunk_shape and any(c == "preserve" for c in chunk_shape):
245+
chunk_shape = chunkmanager.preserve_chunks(
246+
chunk_shape,
247+
shape=shape,
248+
target=chunkmanager.get_auto_chunk_size(),
249+
typesize=getattr(dtype, "itemsize", 8),
250+
previous_chunks=preferred_chunk_shape,
251+
)
252+
239253
chunk_shape = chunkmanager.normalize_chunks(
240254
chunk_shape,
241255
shape=shape,

0 commit comments

Comments
 (0)