feat(array): pa.from_xarray walks readers registered by each carrier's package, and a refusal lists every reason

Aperta
#407 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
48/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
python
Ambito
backend

Direzione di ricerca

Start with pipekit_array/bridges/xarray.py and the referenced q2_xarray_readers.py prototype; review #406 for the NoMatch contract. Implement the registry and from_xarray discovery behavior, including the named DimArray reader. Done means refusals report every reader and reason in order, imports stay lazy, and lint, type checks, and tests pass.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

area:code type:feature

Problem / Request

Add a reader registry to pipekit_array.bridges.xarray and make pa.from_xarray(da) try each registered reader in priority order, returning the first carrier or raising one ValueError that lists each reader's name and reason. DimArray's reader is last and never declines.

Motivation

There are three entry points today, and each assumes the DataArray is its own. The prototype gave each carrier's DataArray to each reader:

Reader GeoArray's DataArray CField's DataArray DimArray's DataArray
GeoArray.from_xarray GeoArray AttributeError ValueError: no grid
CField.from_xarray CField at T, georeference dropped CField at U CField at T
pipekit's from_xarray DimArray, georeference dropped DimArray on (y_c, x_g) DimArray

A chain of the three, each returning a carrier or NoMatch(reason), picked the right carrier in all three cases. coordax does the same with NoCoordinateMatch (CP-D3).

Proposed API

# proposed (CP-D3)
# a reader returns a carrier or NoMatch(reason); one that raises is recorded as declining
def register_reader(name: str, reader: Callable[[xr.DataArray], Any], *, priority: int) -> None: ...

# DataArray → the first carrier a reader claims
def from_xarray(da: xr.DataArray, *, readers: tuple[str, ...] | None = None) -> Any: ...

# ValueError: no carrier reads this DataArray:
#   geoarray: no spatial_ref coordinate
#   gridax: no dim coordinate with an xgcm axis attribute
pa.from_xarray(da, readers=("geoarray", "gridax"))

Reuse

  • pipekit_array/bridges/xarray.py:from_xarray becomes the DimArray reader, unchanged.
  • pipekit_ops.carriers.NoMatch from #406.

References & Existing Code

  • Design: docs/design/coordax_carriers.md in jejjohnson/geostack (merged in jejjohnson/geostack#368), pattern 2 and question CP-O1.
  • Prototype: q2_xarray_readers.py.

Implementation Steps

  • The registry and from_xarray in pipekit_array/bridges/xarray.py, with the discovery CP-O1 decides (entry points pipekit.readers recommended).
  • Keep today's DimArray reader reachable by name (readers=("pipekit",)).

Definition of Done

  • A DataArray no reader claims except DimArray's reads as today.
  • A refusal lists every reader tried, in order, with its reason.
  • A reader that raises is reported with the exception's type and first line.
  • import pipekit_array imports no reader package.
  • Lint, type check and tests green.

Relationships

  • Parent: jejjohnson/geostack#369
  • Blocked by: #406
  • Blocks: jejjohnson/geotoolz#850, jejjohnson/gridax#628, #409
Lingua principale
Python
Stelle
0
Fork
0
Merge medio
3h 50m
PR unite (30g)
143

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di jejjohnson/pipekit

Tutte le issue di jejjohnson/pipekit

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.