Skip to content

Commit 26b4760

Browse files
committed
Make chunk_grid property private
1 parent 6436db6 commit 26b4760

File tree

8 files changed

+115
-119
lines changed

8 files changed

+115
-119
lines changed

docs/design/chunk-grid.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ arr = zarr.create_array(shape=(100, 200), chunks=(10, 20))
200200
arr = zarr.create_array(shape=(60, 100), chunks=[[10, 20, 30], [25, 25, 25, 25]]) # rectilinear
201201

202202
# ChunkGrid as a collection
203-
grid = arr.chunk_grid # behavioral ChunkGrid (bound to array shape)
203+
grid = arr._chunk_grid # behavioral ChunkGrid (bound to array shape)
204204
grid.grid_shape # (10, 10) — number of chunks per dimension
205205
grid.ndim # 2
206206
grid.is_regular # True if all dimensions are Fixed
@@ -351,7 +351,7 @@ new = zarr.from_array(data=src, store=new_store, chunks="keep")
351351
# Preserves rectilinear structure: new.write_chunk_sizes == ((10, 20, 30), (50, 50))
352352
```
353353

354-
When `chunks="keep"`, the logic checks `data.chunk_grid.is_regular`:
354+
When `chunks="keep"`, the logic checks `data._chunk_grid.is_regular`:
355355
- Regular: extracts `data.chunks` (flat tuple) and preserves shards
356356
- Rectilinear: extracts `data.write_chunk_sizes` (nested tuples) and forces shards to None
357357

@@ -372,7 +372,7 @@ Today, `get_chunk_spec()` returns the same `ArraySpec(shape=chunk_grid.chunk_sha
372372

373373
```python
374374
def get_chunk_spec(self, chunk_coords, array_config, prototype) -> ArraySpec:
375-
spec = self.chunk_grid[chunk_coords]
375+
spec = self._chunk_grid[chunk_coords]
376376
return ArraySpec(shape=spec.codec_shape, ...)
377377
```
378378

docs/user-guide/examples/rectilinear_chunks.ipynb

Lines changed: 58 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
"id": "da9139cc",
77
"metadata": {
88
"execution": {
9-
"iopub.execute_input": "2026-03-30T01:03:13.606739Z",
10-
"iopub.status.busy": "2026-03-30T01:03:13.606597Z",
11-
"iopub.status.idle": "2026-03-30T01:03:13.613466Z",
12-
"shell.execute_reply": "2026-03-30T01:03:13.612167Z",
13-
"shell.execute_reply.started": "2026-03-30T01:03:13.606724Z"
9+
"iopub.execute_input": "2026-03-30T13:09:30.606395Z",
10+
"iopub.status.busy": "2026-03-30T13:09:30.606270Z",
11+
"iopub.status.idle": "2026-03-30T13:09:30.611784Z",
12+
"shell.execute_reply": "2026-03-30T13:09:30.608914Z",
13+
"shell.execute_reply.started": "2026-03-30T13:09:30.606380Z"
1414
}
1515
},
1616
"outputs": [],
@@ -51,18 +51,18 @@
5151
"id": "9e9nyjdx06f",
5252
"metadata": {
5353
"execution": {
54-
"iopub.execute_input": "2026-03-30T01:03:13.614308Z",
55-
"iopub.status.busy": "2026-03-30T01:03:13.614115Z",
56-
"iopub.status.idle": "2026-03-30T01:03:27.161046Z",
57-
"shell.execute_reply": "2026-03-30T01:03:27.160587Z",
58-
"shell.execute_reply.started": "2026-03-30T01:03:13.614287Z"
54+
"iopub.execute_input": "2026-03-30T13:09:30.613147Z",
55+
"iopub.status.busy": "2026-03-30T13:09:30.612776Z",
56+
"iopub.status.idle": "2026-03-30T13:09:44.301116Z",
57+
"shell.execute_reply": "2026-03-30T13:09:44.300677Z",
58+
"shell.execute_reply.started": "2026-03-30T13:09:30.613126Z"
5959
}
6060
},
6161
"outputs": [
6262
{
6363
"data": {
6464
"text/plain": [
65-
"<donfig.config_obj.ConfigSet at 0x109d94ec0>"
65+
"<donfig.config_obj.ConfigSet at 0x10e48cec0>"
6666
]
6767
},
6868
"execution_count": 2,
@@ -103,11 +103,11 @@
103103
"id": "v6cot74r1gq",
104104
"metadata": {
105105
"execution": {
106-
"iopub.execute_input": "2026-03-30T01:03:27.161531Z",
107-
"iopub.status.busy": "2026-03-30T01:03:27.161384Z",
108-
"iopub.status.idle": "2026-03-30T01:03:46.210431Z",
109-
"shell.execute_reply": "2026-03-30T01:03:46.209459Z",
110-
"shell.execute_reply.started": "2026-03-30T01:03:27.161522Z"
106+
"iopub.execute_input": "2026-03-30T13:09:44.301615Z",
107+
"iopub.status.busy": "2026-03-30T13:09:44.301466Z",
108+
"iopub.status.idle": "2026-03-30T13:09:45.297053Z",
109+
"shell.execute_reply": "2026-03-30T13:09:45.292702Z",
110+
"shell.execute_reply.started": "2026-03-30T13:09:44.301605Z"
111111
}
112112
},
113113
"outputs": [
@@ -117,7 +117,7 @@
117117
"text": [
118118
"Members: [('cell_ids', <Array object_store://HTTPStore(\"https://data-taos.ifremer.fr/GRID4EARTH/no_chunk_healpix.zarr\")/cell_ids shape=(222442,) dtype=int64>), ('da', <Array object_store://HTTPStore(\"https://data-taos.ifremer.fr/GRID4EARTH/no_chunk_healpix.zarr\")/da shape=(222442,) dtype=float32>)]\n",
119119
"Attrs: {}\n",
120-
"Chunk grid: ChunkGrid(dimensions=(FixedDimension(size=55611, extent=222442),), _is_regular=True)\n"
120+
"Write chunk sizes: ((55611, 55611, 55611, 55609),)\n"
121121
]
122122
}
123123
],
@@ -129,7 +129,7 @@
129129
"\n",
130130
"print(\"Members:\", list(g.members()))\n",
131131
"print(\"Attrs:\", dict(g.attrs))\n",
132-
"print(\"Chunk grid:\", arr.chunk_grid)"
132+
"print(\"Write chunk sizes:\", arr.write_chunk_sizes)"
133133
]
134134
},
135135
{
@@ -148,11 +148,11 @@
148148
"id": "90bc91b9",
149149
"metadata": {
150150
"execution": {
151-
"iopub.execute_input": "2026-03-30T01:03:46.211439Z",
152-
"iopub.status.busy": "2026-03-30T01:03:46.211138Z",
153-
"iopub.status.idle": "2026-03-30T01:03:47.632389Z",
154-
"shell.execute_reply": "2026-03-30T01:03:47.631887Z",
155-
"shell.execute_reply.started": "2026-03-30T01:03:46.211416Z"
151+
"iopub.execute_input": "2026-03-30T13:09:45.301060Z",
152+
"iopub.status.busy": "2026-03-30T13:09:45.299959Z",
153+
"iopub.status.idle": "2026-03-30T13:09:46.662995Z",
154+
"shell.execute_reply": "2026-03-30T13:09:46.662527Z",
155+
"shell.execute_reply.started": "2026-03-30T13:09:45.301022Z"
156156
}
157157
},
158158
"outputs": [],
@@ -170,11 +170,11 @@
170170
"id": "0d7785b0-d72f-4ef8-8a57-91d61f07be96",
171171
"metadata": {
172172
"execution": {
173-
"iopub.execute_input": "2026-03-30T01:03:47.633034Z",
174-
"iopub.status.busy": "2026-03-30T01:03:47.632792Z",
175-
"iopub.status.idle": "2026-03-30T01:03:47.635838Z",
176-
"shell.execute_reply": "2026-03-30T01:03:47.635478Z",
177-
"shell.execute_reply.started": "2026-03-30T01:03:47.633024Z"
173+
"iopub.execute_input": "2026-03-30T13:09:46.663527Z",
174+
"iopub.status.busy": "2026-03-30T13:09:46.663301Z",
175+
"iopub.status.idle": "2026-03-30T13:09:46.666266Z",
176+
"shell.execute_reply": "2026-03-30T13:09:46.665875Z",
177+
"shell.execute_reply.started": "2026-03-30T13:09:46.663516Z"
178178
}
179179
},
180180
"outputs": [
@@ -200,11 +200,11 @@
200200
"id": "72c80224-dcac-4724-8caf-5717b29a25d5",
201201
"metadata": {
202202
"execution": {
203-
"iopub.execute_input": "2026-03-30T01:03:47.636213Z",
204-
"iopub.status.busy": "2026-03-30T01:03:47.636138Z",
205-
"iopub.status.idle": "2026-03-30T01:03:47.643387Z",
206-
"shell.execute_reply": "2026-03-30T01:03:47.642743Z",
207-
"shell.execute_reply.started": "2026-03-30T01:03:47.636205Z"
203+
"iopub.execute_input": "2026-03-30T13:09:46.666584Z",
204+
"iopub.status.busy": "2026-03-30T13:09:46.666509Z",
205+
"iopub.status.idle": "2026-03-30T13:09:46.673617Z",
206+
"shell.execute_reply": "2026-03-30T13:09:46.672827Z",
207+
"shell.execute_reply.started": "2026-03-30T13:09:46.666576Z"
208208
}
209209
},
210210
"outputs": [
@@ -238,11 +238,11 @@
238238
"id": "a79a281b-ca74-49c3-a467-60490a4ad63e",
239239
"metadata": {
240240
"execution": {
241-
"iopub.execute_input": "2026-03-30T01:03:47.643801Z",
242-
"iopub.status.busy": "2026-03-30T01:03:47.643715Z",
243-
"iopub.status.idle": "2026-03-30T01:03:47.648805Z",
244-
"shell.execute_reply": "2026-03-30T01:03:47.648326Z",
245-
"shell.execute_reply.started": "2026-03-30T01:03:47.643792Z"
241+
"iopub.execute_input": "2026-03-30T13:09:46.674098Z",
242+
"iopub.status.busy": "2026-03-30T13:09:46.673995Z",
243+
"iopub.status.idle": "2026-03-30T13:09:46.690488Z",
244+
"shell.execute_reply": "2026-03-30T13:09:46.686144Z",
245+
"shell.execute_reply.started": "2026-03-30T13:09:46.674089Z"
246246
}
247247
},
248248
"outputs": [
@@ -278,19 +278,19 @@
278278
"id": "ribguojdr0s",
279279
"metadata": {
280280
"execution": {
281-
"iopub.execute_input": "2026-03-30T01:03:47.649560Z",
282-
"iopub.status.busy": "2026-03-30T01:03:47.649480Z",
283-
"iopub.status.idle": "2026-03-30T01:03:47.943997Z",
284-
"shell.execute_reply": "2026-03-30T01:03:47.943488Z",
285-
"shell.execute_reply.started": "2026-03-30T01:03:47.649552Z"
281+
"iopub.execute_input": "2026-03-30T13:09:46.691041Z",
282+
"iopub.status.busy": "2026-03-30T13:09:46.690923Z",
283+
"iopub.status.idle": "2026-03-30T13:09:47.241836Z",
284+
"shell.execute_reply": "2026-03-30T13:09:47.241361Z",
285+
"shell.execute_reply.started": "2026-03-30T13:09:46.691030Z"
286286
}
287287
},
288288
"outputs": [
289289
{
290290
"name": "stdout",
291291
"output_type": "stream",
292292
"text": [
293-
"Written to: /var/folders/70/hc_nynms54d8lp67z4rsfctc0000gp/T/tmpgjlmnfff/healpix_rectilinear.zarr\n"
293+
"Written to: /var/folders/70/hc_nynms54d8lp67z4rsfctc0000gp/T/tmp30rjewd0/healpix_rectilinear.zarr\n"
294294
]
295295
}
296296
],
@@ -331,11 +331,11 @@
331331
"id": "mpdn5hxp7lp",
332332
"metadata": {
333333
"execution": {
334-
"iopub.execute_input": "2026-03-30T01:03:47.944360Z",
335-
"iopub.status.busy": "2026-03-30T01:03:47.944287Z",
336-
"iopub.status.idle": "2026-03-30T01:03:47.946825Z",
337-
"shell.execute_reply": "2026-03-30T01:03:47.946372Z",
338-
"shell.execute_reply.started": "2026-03-30T01:03:47.944352Z"
334+
"iopub.execute_input": "2026-03-30T13:09:47.242174Z",
335+
"iopub.status.busy": "2026-03-30T13:09:47.242097Z",
336+
"iopub.status.idle": "2026-03-30T13:09:47.244629Z",
337+
"shell.execute_reply": "2026-03-30T13:09:47.244126Z",
338+
"shell.execute_reply.started": "2026-03-30T13:09:47.242166Z"
339339
}
340340
},
341341
"outputs": [
@@ -367,38 +367,36 @@
367367
},
368368
{
369369
"cell_type": "code",
370-
"execution_count": 10,
370+
"execution_count": 13,
371371
"id": "308gxly6r3j",
372372
"metadata": {
373373
"execution": {
374-
"iopub.execute_input": "2026-03-30T01:03:47.947072Z",
375-
"iopub.status.busy": "2026-03-30T01:03:47.946996Z",
376-
"iopub.status.idle": "2026-03-30T01:03:47.967534Z",
377-
"shell.execute_reply": "2026-03-30T01:03:47.967022Z",
378-
"shell.execute_reply.started": "2026-03-30T01:03:47.947061Z"
374+
"iopub.execute_input": "2026-03-30T13:11:17.611493Z",
375+
"iopub.status.busy": "2026-03-30T13:11:17.610692Z",
376+
"iopub.status.idle": "2026-03-30T13:11:17.655199Z",
377+
"shell.execute_reply": "2026-03-30T13:11:17.654529Z",
378+
"shell.execute_reply.started": "2026-03-30T13:11:17.611441Z"
379379
}
380380
},
381381
"outputs": [
382382
{
383383
"name": "stdout",
384384
"output_type": "stream",
385385
"text": [
386-
"Round-trip chunk sizes: Frozen({'cell_ids': (25, 645, 1510, 2363, 3203, 74, 769, 3963, 4096, 233, 1603, 2450, 4096, 4096, 3327, 4047, 4096, 4096, 1278, 2113, 4096, 3879, 4096, 3842, 2173, 983, 4046, 2187, 4095, 1369, 4096, 4096, 4096, 4096, 3515, 1395, 4096, 3622, 4096, 4096, 3875, 4096, 4096, 4096, 4096, 4096, 2034, 4096, 358, 3991, 4096, 4096, 4096, 4096, 2714, 1210, 4096, 4096, 4096, 4096, 92, 3826, 4096, 2629, 4096, 1438, 4096, 353, 4078, 3410, 2407, 226, 132, 2738, 1223, 23)})\n",
387-
"Regular grid: False\n"
386+
"Round-trip chunk sizes: Frozen({'cell_ids': (25, 645, 1510, 2363, 3203, 74, 769, 3963, 4096, 233, 1603, 2450, 4096, 4096, 3327, 4047, 4096, 4096, 1278, 2113, 4096, 3879, 4096, 3842, 2173, 983, 4046, 2187, 4095, 1369, 4096, 4096, 4096, 4096, 3515, 1395, 4096, 3622, 4096, 4096, 3875, 4096, 4096, 4096, 4096, 4096, 2034, 4096, 358, 3991, 4096, 4096, 4096, 4096, 2714, 1210, 4096, 4096, 4096, 4096, 92, 3826, 4096, 2629, 4096, 1438, 4096, 353, 4078, 3410, 2407, 226, 132, 2738, 1223, 23)})\n"
388387
]
389388
}
390389
],
391390
"source": [
392391
"roundtrip = xr.open_zarr(output_path, zarr_format=3, consolidated=False)\n",
393392
"\n",
394-
"print(\"Round-trip chunk sizes:\", roundtrip.chunks)\n",
395-
"print(\"Regular grid:\", roundtrip[\"da\"].variable.encoding.get(\"chunks\") == tuple(chunk_sizes.tolist()))"
393+
"print(\"Round-trip chunk sizes:\", roundtrip.chunks)"
396394
]
397395
},
398396
{
399397
"cell_type": "code",
400398
"execution_count": null,
401-
"id": "d3c32f1c-2c4f-403f-a4e8-98c6582eef96",
399+
"id": "e8d42341-c242-44f5-ad6a-491370e3ffab",
402400
"metadata": {},
403401
"outputs": [],
404402
"source": []

0 commit comments

Comments
 (0)