|
1 | 1 | import itertools |
2 | | -from collections.abc import Callable, Hashable, Iterator, Mapping |
| 2 | +from collections.abc import Callable, Hashable, Iterable, Iterator, Mapping |
3 | 3 | from typing import Any |
4 | 4 |
|
5 | 5 | import numpy as np |
@@ -402,22 +402,31 @@ def _parse_schema(ds: xr.Dataset) -> pa.Schema: |
402 | 402 | PartitionBounds = dict[str, tuple[Any, Any, str]] |
403 | 403 |
|
404 | 404 |
|
405 | | -def _block_metadata(coord_arrays: dict, block: Block) -> PartitionBounds: |
| 405 | +def _block_metadata( |
| 406 | + coord_arrays: dict, |
| 407 | + block: Block, |
| 408 | + dims: Iterable[Hashable] | None = None, |
| 409 | +) -> PartitionBounds: |
406 | 410 | """Compute min/max coordinate values for a single partition block. |
407 | 411 |
|
408 | 412 | Args: |
409 | 413 | coord_arrays: Pre-materialised coordinate arrays keyed by dimension name |
410 | 414 | string. Hoist this outside any loop to avoid repeated remote I/O |
411 | 415 | for Zarr-backed datasets. |
412 | 416 | block: A single block slice dict from block_slices(). |
| 417 | + dims: Optional restriction to a subset of dims to compute. Used by |
| 418 | + ``read_xarray_table`` to skip unchunked dims whose bounds are |
| 419 | + constant across all partitions and have been precomputed once. |
| 420 | + Defaults to all dims present in ``block``. |
413 | 421 |
|
414 | 422 | Returns: |
415 | 423 | Dict mapping dimension name to (min_value, max_value, dtype_str). |
416 | 424 | Dimensions with an empty slice are omitted; the Rust pruning logic |
417 | 425 | treats missing dimensions conservatively (never prunes on them). |
418 | 426 | """ |
| 427 | + items = ((d, block[d]) for d in dims) if dims is not None else block.items() |
419 | 428 | ranges: PartitionBounds = {} |
420 | | - for dim, slc in block.items(): |
| 429 | + for dim, slc in items: |
421 | 430 | coord_values = coord_arrays[str(dim)][slc] |
422 | 431 | if len(coord_values) == 0: |
423 | 432 | continue |
|
0 commit comments