@@ -812,6 +812,8 @@ def chunk(
812
812
chunks = either_dict_or_kwargs (chunks , chunks_kwargs , "chunk" )
813
813
814
814
if is_dict_like (chunks ):
815
+ # turns dict[str, tuple[in, ..]] -> dict[int, tuple[int, ...]]
816
+
815
817
# This method of iteration allows for duplicated dimension names, GH8579
816
818
chunks = {
817
819
dim_number : chunks [dim ]
@@ -825,6 +827,21 @@ def chunk(
825
827
# if is_dict_like(chunks) and chunks != {}:
826
828
# chunks = tuple(chunks.get(n, s) for n, s in enumerate(data_old.shape)) # type: ignore[assignment]
827
829
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
+
828
845
print (f"hopefully normalized chunks = { chunks } " )
829
846
830
847
# 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(
846
863
ndata = ImplicitToExplicitIndexingAdapter (data_old , OuterIndexer ) # type: ignore[assignment]
847
864
848
865
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)
849
867
chunks = tuple (chunks .get (n , s ) for n , s in enumerate (ndata .shape )) # type: ignore[assignment]
850
868
851
869
chunkmanager = guess_chunkmanager (chunked_array_type )
0 commit comments