Skip to content

Commit 556161d

Browse files
committed
fixed bug with chunks passed as dict
1 parent 3cadd53 commit 556161d

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

xarray/namedarray/core.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -812,6 +812,8 @@ def chunk(
812812
chunks = either_dict_or_kwargs(chunks, chunks_kwargs, "chunk")
813813

814814
if is_dict_like(chunks):
815+
# turns dict[str, tuple[in, ..]] -> dict[int, tuple[int, ...]]
816+
815817
# This method of iteration allows for duplicated dimension names, GH8579
816818
chunks = {
817819
dim_number: chunks[dim]
@@ -825,6 +827,21 @@ def chunk(
825827
# if is_dict_like(chunks) and chunks != {}:
826828
# chunks = tuple(chunks.get(n, s) for n, s in enumerate(data_old.shape)) # type: ignore[assignment]
827829

830+
old_chunks = data_old.chunks
831+
832+
if is_dict_like(chunks):
833+
# turns dict[int, tuple[int, ...]] -> tuple[tuple[int, ...], ...], filling in unspecified dimensions using previous chunking
834+
chunks = tuple(
835+
[
836+
(
837+
chunks[dim_number]
838+
if dim_number in chunks.keys()
839+
else old_chunks[dim_number]
840+
)
841+
for dim_number in range(self.ndim)
842+
]
843+
)
844+
828845
print(f"hopefully normalized chunks = {chunks}")
829846

830847
# Assume any chunked array supports .rechunk - if it doesn't then at least a clear AttributeError will be raised.
@@ -846,6 +863,7 @@ def chunk(
846863
ndata = ImplicitToExplicitIndexingAdapter(data_old, OuterIndexer) # type: ignore[assignment]
847864

848865
if is_dict_like(chunks):
866+
# turns dict[int, tuple[int, ...]] -> tuple[tuple[int, ...], ...], filling in unspecified dimensions using full length along each axis (i.e. array shape)
849867
chunks = tuple(chunks.get(n, s) for n, s in enumerate(ndata.shape)) # type: ignore[assignment]
850868

851869
chunkmanager = guess_chunkmanager(chunked_array_type)

0 commit comments

Comments
 (0)