Skip to content

Commit be8e17e

Browse files
mraspauddcherian
andauthored
Support duplicate dimensions in .chunk (#9099)
* Allow duplicate dimensions in chunking * Address review comments * fix whats-new * add comment * Update xarray/tests/test_dask.py --------- Co-authored-by: Deepak Cherian <deepak@cherian.net> Co-authored-by: Deepak Cherian <dcherian@users.noreply.github.com>
1 parent 32e1f33 commit be8e17e

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

doc/whats-new.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ v2024.06.1 (unreleased)
2222

2323
New Features
2424
~~~~~~~~~~~~
25-
25+
- Allow chunking for arrays with duplicated dimension names (:issue:`8759`, :pull:`9099`).
26+
By `Martin Raspaud <https://github.com/mraspaud>`_.
2627

2728
Breaking changes
2829
~~~~~~~~~~~~~~~~
@@ -73,7 +74,6 @@ Bug fixes
7374
support arbitrary kwargs such as ``order`` for polynomial interpolation (:issue:`8762`).
7475
By `Nicolas Karasiak <https://github.com/nkarasiak>`_.
7576

76-
7777
Documentation
7878
~~~~~~~~~~~~~
7979
- Add link to CF Conventions on packed data and sentence on type determination in the I/O user guide (:issue:`9041`, :pull:`9045`).

xarray/namedarray/core.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -812,7 +812,12 @@ def chunk(
812812
chunks = either_dict_or_kwargs(chunks, chunks_kwargs, "chunk")
813813

814814
if is_dict_like(chunks):
815-
chunks = {self.get_axis_num(dim): chunk for dim, chunk in chunks.items()}
815+
# This method of iteration allows for duplicated dimension names, GH8579
816+
chunks = {
817+
dim_number: chunks[dim]
818+
for dim_number, dim in enumerate(self.dims)
819+
if dim in chunks
820+
}
816821

817822
chunkmanager = guess_chunkmanager(chunked_array_type)
818823

xarray/tests/test_dask.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,13 @@ def counting_get(*args, **kwargs):
638638

639639
assert count[0] == 1
640640

641+
def test_duplicate_dims(self):
642+
data = np.random.normal(size=(4, 4))
643+
arr = DataArray(data, dims=("x", "x"))
644+
chunked_array = arr.chunk({"x": 2})
645+
assert chunked_array.chunks == ((2, 2), (2, 2))
646+
assert chunked_array.chunksizes == {"x": (2, 2)}
647+
641648
def test_stack(self):
642649
data = da.random.normal(size=(2, 3, 4), chunks=(1, 3, 4))
643650
arr = DataArray(data, dims=("w", "x", "y"))

0 commit comments

Comments
 (0)