Commit 6e7f2f3
refactor: simplify internal chunk representation (#3899)
* refactor: rename guess_chunks to more clearly indicate that it guesses regular chunks
* fix: use the same chunk normalization path in all cases
Previously rectilinear chunk grids and regular chunk grids normalized chunks inconsistently.
This change ensures that chunk specifications are always normalized by the same routines in all cases.
This change also ensures that chunks=(-1, ...) consistently normalizes to a full length chunk along that axis.
* refactor: use newtype pattern
* docs: changelog
* fix: handle 0-length arrays
* test: test untested cases of chunk normalization
* fix: don't accept inane input
* test: check error states in normalize_chunks_1d
* refactor: make resolvedchunking recursive to support nested sharding
* test: add _assert_chunks_equal helper for ChunksTuple
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* perf: ChunksTuple uses 1D int64 arrays per axis
Switch normalize_chunks_1d to return np.ndarray[tuple[int], np.dtype[np.int64]]
instead of tuple[int, ...]. The uniform-chunks branch now constructs in O(1)
via np.full, recovering the single-allocation fast path that regressed when
the canonical ChunksTuple representation was introduced.
Update create_chunk_grid_metadata in v3.py to convert arrays to tuples of ints
before passing to is_regular_nd and RectilinearChunkGridMetadata, keeping those
downstream functions' signatures unchanged.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* revert: undo out-of-scope v3.py changes from 14788aa
The previous commit 14788aa was meant to only touch chunk_grids.py
(Tasks 2+3 of the ChunksTuple → int64-array refactor). It also
modified create_chunk_grid_metadata in v3.py — that change belongs
to a later task with a different approach (widen annotations rather
than materialize tuples) and a better perf profile.
Restoring v3.py to its pre-14788aa state. The proper v3.py change
will land in a follow-up commit.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* fix: cast ChunksTuple elements to int at consumer sites in array.py
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* fix: widen is_regular_* annotations and cast ChunksTuple in create_chunk_grid_metadata
Accept ndarray[int64] in is_regular_1d/is_regular_nd alongside Sequence[int].
Cast only the first element per axis on the regular path so D ints are
allocated rather than N*D. Materialize fully on the rectilinear path because
_validate_chunk_shapes checks isinstance(dim_spec, int) which rejects np.int64.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* test: cast ChunksTuple elements to int in create_array_metadata fixture
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* test: rewrite ChunksTuple equality checks and add return-type characterization
Use _assert_chunks_equal for the three call sites that compared a tuple of
int64 arrays against a tuple of int tuples. Add three small tests asserting
that normalize_chunks_1d returns a 1D int64 ndarray for uniform, explicit-list,
and -1 sentinel inputs.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* perf: vectorize is_regular_1d for ndarray inputs
Per-element Python iteration over a 100K-element int64 array dominated
create_array runtime on the (10**8,) chunks=(1000,) regression case
(~6 ms in is_regular_nd, downstream of ChunksTuple normalization).
Dispatch on np.ndarray and use a single vectorized comparison instead.
End-to-end create_array on the regression case: ~7.9 ms -> ~0.6 ms.
Promote numpy to a runtime import (was TYPE_CHECKING-only) for the
isinstance dispatch.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* refactor: rename ResolvedChunking to ChunkLayout
Names the structure (a layout) rather than the operation that produced it.
Reads cleanly for both sharded and unsharded cases, fits the recursive
inner-layout pattern, and is what one reaches for when reading the code cold.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* chore: add informative error for invalid chunk grid parameter
* chore: make tests compact
* fix: typos
* test: add tests for regular grid helper functions
* fix: reject chunks=True
* docs: update changelog
* docs: remove unneeded changelog entry
* test: test for explicit 0-sized chunk length rejection
* chore: hoist imports
* refactor: add as_regular_shape helper routine
* Update src/zarr/core/chunk_grids.py
Co-authored-by: Max Jones <14077947+maxrjones@users.noreply.github.com>
* Update src/zarr/core/chunk_grids.py
Co-authored-by: Max Jones <14077947+maxrjones@users.noreply.github.com>
* Update src/zarr/core/array.py
Co-authored-by: Max Jones <14077947+maxrjones@users.noreply.github.com>
* chore: cleanup
---------
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-authored-by: Max Jones <14077947+maxrjones@users.noreply.github.com>1 parent f9c53d5 commit 6e7f2f3
9 files changed
Lines changed: 671 additions & 225 deletions
File tree
- changes
- src/zarr/core
- metadata
- tests
- test_codecs
- test_metadata
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
| 42 | + | |
42 | 43 | | |
43 | | - | |
44 | | - | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
45 | 49 | | |
46 | 50 | | |
47 | 51 | | |
| |||
121 | 125 | | |
122 | 126 | | |
123 | 127 | | |
124 | | - | |
125 | | - | |
| 128 | + | |
126 | 129 | | |
127 | | - | |
128 | 130 | | |
129 | 131 | | |
130 | 132 | | |
| |||
411 | 413 | | |
412 | 414 | | |
413 | 415 | | |
414 | | - | |
415 | | - | |
| 416 | + | |
416 | 417 | | |
417 | 418 | | |
418 | 419 | | |
| |||
438 | 439 | | |
439 | 440 | | |
440 | 441 | | |
441 | | - | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
442 | 447 | | |
443 | 448 | | |
444 | 449 | | |
| |||
469 | 474 | | |
470 | 475 | | |
471 | 476 | | |
472 | | - | |
473 | | - | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
474 | 480 | | |
475 | | - | |
| 481 | + | |
| 482 | + | |
476 | 483 | | |
477 | 484 | | |
478 | 485 | | |
| |||
4385 | 4392 | | |
4386 | 4393 | | |
4387 | 4394 | | |
| 4395 | + | |
4388 | 4396 | | |
4389 | 4397 | | |
4390 | 4398 | | |
| |||
4397 | 4405 | | |
4398 | 4406 | | |
4399 | 4407 | | |
4400 | | - | |
4401 | | - | |
4402 | | - | |
4403 | | - | |
4404 | | - | |
4405 | | - | |
| 4408 | + | |
4406 | 4409 | | |
4407 | 4410 | | |
4408 | 4411 | | |
| |||
4412 | 4415 | | |
4413 | 4416 | | |
4414 | 4417 | | |
4415 | | - | |
4416 | | - | |
| 4418 | + | |
| 4419 | + | |
| 4420 | + | |
| 4421 | + | |
| 4422 | + | |
| 4423 | + | |
| 4424 | + | |
4417 | 4425 | | |
4418 | | - | |
4419 | | - | |
4420 | 4426 | | |
4421 | | - | |
4422 | | - | |
4423 | | - | |
4424 | | - | |
4425 | | - | |
4426 | | - | |
4427 | | - | |
4428 | | - | |
4429 | | - | |
4430 | | - | |
4431 | | - | |
4432 | | - | |
4433 | | - | |
4434 | | - | |
4435 | | - | |
4436 | | - | |
4437 | | - | |
4438 | | - | |
4439 | | - | |
4440 | | - | |
| 4427 | + | |
4441 | 4428 | | |
4442 | | - | |
| 4429 | + | |
| 4430 | + | |
| 4431 | + | |
4443 | 4432 | | |
4444 | | - | |
4445 | | - | |
| 4433 | + | |
| 4434 | + | |
4446 | 4435 | | |
4447 | 4436 | | |
4448 | | - | |
| 4437 | + | |
4449 | 4438 | | |
4450 | 4439 | | |
4451 | | - | |
| 4440 | + | |
4452 | 4441 | | |
4453 | 4442 | | |
4454 | 4443 | | |
| |||
4472 | 4461 | | |
4473 | 4462 | | |
4474 | 4463 | | |
4475 | | - | |
| 4464 | + | |
4476 | 4465 | | |
4477 | 4466 | | |
4478 | 4467 | | |
| |||
4488 | 4477 | | |
4489 | 4478 | | |
4490 | 4479 | | |
| 4480 | + | |
4491 | 4481 | | |
4492 | | - | |
| 4482 | + | |
| 4483 | + | |
4493 | 4484 | | |
4494 | 4485 | | |
4495 | 4486 | | |
4496 | 4487 | | |
4497 | 4488 | | |
4498 | 4489 | | |
4499 | | - | |
| 4490 | + | |
4500 | 4491 | | |
4501 | | - | |
4502 | | - | |
4503 | | - | |
4504 | | - | |
4505 | | - | |
4506 | 4492 | | |
4507 | | - | |
| 4493 | + | |
4508 | 4494 | | |
4509 | | - | |
| 4495 | + | |
4510 | 4496 | | |
4511 | 4497 | | |
4512 | | - | |
4513 | 4498 | | |
4514 | | - | |
4515 | 4499 | | |
4516 | 4500 | | |
4517 | 4501 | | |
4518 | 4502 | | |
4519 | | - | |
4520 | | - | |
4521 | | - | |
4522 | | - | |
4523 | | - | |
4524 | | - | |
4525 | 4503 | | |
4526 | 4504 | | |
4527 | 4505 | | |
| |||
0 commit comments