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

Open
#407 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
48/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Active
Tech stack
python
Domain
backend

Research direction

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.

Written by the indexing model from the issue text.

Description

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
Dominant language
Python
Stars
0
Forks
0
Avg merge
3h 50m
Merged PRs (30d)
143

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from jejjohnson/pipekit

All issues in jejjohnson/pipekit

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.