MCPcopy Index your code
hub / github.com/pydata/xarray / build_grid_chunks

Function build_grid_chunks

xarray/backends/chunks.py:134–153  ·  view source on GitHub ↗
(
    size: int,
    chunk_size: int,
    region: slice | None = None,
)

Source from the content-addressed store, hash-verified

132
133
134def build_grid_chunks(
135 size: int,
136 chunk_size: int,
137 region: slice | None = None,
138) -> tuple[int, ...]:
139 if region is None:
140 region = slice(0, size)
141
142 region_start = region.start or 0
143 # Generate the zarr chunks inside the region of this dim
144 chunks_on_region = [chunk_size - (region_start % chunk_size)]
145 if chunks_on_region[0] >= size:
146 # This is useful for the scenarios where the chunk_size are bigger
147 # than the variable chunks, which can happens when the user specifies
148 # the enc_chunks manually.
149 return (size,)
150 chunks_on_region.extend([chunk_size] * ((size - chunks_on_region[0]) // chunk_size))
151 if (size - chunks_on_region[0]) % chunk_size != 0:
152 chunks_on_region.append((size - chunks_on_region[0]) % chunk_size)
153 return tuple(chunks_on_region)
154
155
156def grid_rechunk(

Callers 2

test_build_grid_chunksFunction · 0.90
grid_rechunkFunction · 0.85

Calls

no outgoing calls

Tested by 1

test_build_grid_chunksFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…