Skip to content

Commit d6c3767

Browse files
max-sixtyIllviljan
andauthored
Refine chunks=None handling (#8249)
* Refine `chunks=None` handling Based on comment in #8247. This doesn't make it perfect, but allows the warning to get hit and clarifies the type comment, as a stop-gap * Test avoiding redefinition --------- Co-authored-by: Illviljan <[email protected]>
1 parent dbcf6a7 commit d6c3767

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

xarray/core/dataset.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2634,21 +2634,20 @@ def chunk(
26342634
xarray.unify_chunks
26352635
dask.array.from_array
26362636
"""
2637-
if chunks is None and chunks_kwargs is None:
2637+
if chunks is None and not chunks_kwargs:
26382638
warnings.warn(
26392639
"None value for 'chunks' is deprecated. "
26402640
"It will raise an error in the future. Use instead '{}'",
26412641
category=FutureWarning,
26422642
)
26432643
chunks = {}
2644-
2645-
if not isinstance(chunks, Mapping):
2646-
# We need to ignore since mypy doesn't recognize this can't be `None`
2647-
chunks = dict.fromkeys(self.dims, chunks) # type: ignore[arg-type]
2644+
chunks_mapping: Mapping[Any, Any]
2645+
if not isinstance(chunks, Mapping) and chunks is not None:
2646+
chunks_mapping = dict.fromkeys(self.dims, chunks)
26482647
else:
2649-
chunks = either_dict_or_kwargs(chunks, chunks_kwargs, "chunk")
2648+
chunks_mapping = either_dict_or_kwargs(chunks, chunks_kwargs, "chunk")
26502649

2651-
bad_dims = chunks.keys() - self.dims.keys()
2650+
bad_dims = chunks_mapping.keys() - self.dims.keys()
26522651
if bad_dims:
26532652
raise ValueError(
26542653
f"chunks keys {tuple(bad_dims)} not found in data dimensions {tuple(self.dims)}"
@@ -2662,7 +2661,7 @@ def chunk(
26622661
k: _maybe_chunk(
26632662
k,
26642663
v,
2665-
chunks,
2664+
chunks_mapping,
26662665
token,
26672666
lock,
26682667
name_prefix,

0 commit comments

Comments
 (0)