Skip to content

Commit

Permalink
add encodings["preferred_chunks"], used in open_dataset instead of en… (
Browse files Browse the repository at this point in the history
pydata#4669)

* add encodings["preferred_chunks"], used in open_dataset instead of encodings["chunks"]

* modify preferred_chunks: now it's a dictionary not a list

* fix if preferred_chunks is not defined
  • Loading branch information
aurghs authored Dec 17, 2020
1 parent 778a16e commit 91318d2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
1 change: 1 addition & 0 deletions xarray/backends/zarr.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ def open_store_variable(self, name, zarr_array):
attributes = dict(attributes)
encoding = {
"chunks": zarr_array.chunks,
"preferred_chunks": dict(zip(dimensions, zarr_array.chunks)),
"compressor": zarr_array.compressor,
"filters": zarr_array.filters,
}
Expand Down
6 changes: 4 additions & 2 deletions xarray/core/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,8 +389,10 @@ def _get_chunk(var, chunks):
if isinstance(chunks, int) or (chunks == "auto"):
chunks = dict.fromkeys(var.dims, chunks)

preferred_chunks_list = var.encoding.get("chunks", {})
preferred_chunks = dict(zip(var.dims, var.encoding.get("chunks", {})))
preferred_chunks = var.encoding.get("preferred_chunks", {})
preferred_chunks_list = [
preferred_chunks.get(dim, shape) for dim, shape in zip(var.dims, var.shape)
]

chunks_list = [
chunks.get(dim, None) or preferred_chunks.get(dim, None) for dim in var.dims
Expand Down

0 comments on commit 91318d2

Please sign in to comment.