Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support duplicate dimensions in .chunk #9099

Merged
merged 7 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions doc/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ v2024.06.1 (unreleased)

New Features
~~~~~~~~~~~~

- Allow chunking for arrays with duplicated dimension names (:issue:`8759`, :pull:`9099`).
By `Martin Raspaud <https://github.com/mraspaud>`_.

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


Documentation
~~~~~~~~~~~~~
- Add link to CF Conventions on packed data and sentence on type determination in the I/O user guide (:issue:`9041`, :pull:`9045`).
Expand Down
7 changes: 6 additions & 1 deletion xarray/namedarray/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,12 @@ def chunk(
chunks = either_dict_or_kwargs(chunks, chunks_kwargs, "chunk")

if is_dict_like(chunks):
chunks = {self.get_axis_num(dim): chunk for dim, chunk in chunks.items()}
# This method of iteration allows for duplicated dimension names, GH8579
chunks = {
dim_number: chunks[dim]
for dim_number, dim in enumerate(self.dims)
if dim in chunks
}

chunkmanager = guess_chunkmanager(chunked_array_type)

Expand Down
6 changes: 6 additions & 0 deletions xarray/tests/test_dask.py
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,12 @@ def counting_get(*args, **kwargs):

assert count[0] == 1

def test_duplicate_dims(self):
data = np.random.normal(size=(4, 4))
arr = DataArray(data, dims=("x", "x"))
chunked_array = arr.chunk({"x": 2})
assert chunked_array.chunks == ((2, 2), (2, 2))
dcherian marked this conversation as resolved.
Show resolved Hide resolved

def test_stack(self):
data = da.random.normal(size=(2, 3, 4), chunks=(1, 3, 4))
arr = DataArray(data, dims=("w", "x", "y"))
Expand Down
Loading