feat(ops): Coordinate, NoMatch and isel_coords in pipekit-ops, and DimArray stores its labels as Labels coordinates

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

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
38/100
Issue type
Feature
Clarity
Clearly specified
Activity status
Active
Tech stack
python
Domain
api, backend

Research direction

Start with pipekit_ops/carriers/_coords.py, pipekit_array/named/, and pipekit_array/named/_carrier.py; use the referenced design and q1_coordinates.py as guides. Implement the coordinate protocol and migrate DimArray label handling, then update the adapter documentation. Done means the listed slicing oracle, adapter tests, import constraint, JIT behavior, lint, and type checks all pass.

Written by the indexing model from the issue text.

Description

area:code type:feature

Problem / Request

Add the coordinate protocol to pipekit-ops (Coordinate, NoMatch, isel_coords) and a Labels coordinate to pipekit-array, and make DimArray store its labels as Labels, so slicing metadata is written once for every carrier instead of in each adapter.

Motivation

Each adapter slices its own metadata in isel, rebuilds itself in rewrap, and decides what it becomes when a dim goes: DimArrayAdapter spends 65 lines on isel, rewrap and relabel. geoarray already has a better shape, a Coordinate per dim that slices itself (geoarray/_src/coords.py), and coordax has the same (Coordinate._isel). Lifting it into pipekit-ops lets gridax and geoarray share it (CP-D1).

Proposed API

# Shapes: (member, y, x) = (3, 6, 8)

# proposed (CP-D1), pipekit_ops.carriers
class Coordinate(Protocol):
    @property
    def dim(self) -> str: ...
    @property
    def size(self) -> int: ...
    @property
    def labels(self) -> tuple[Any, ...] | None: ...
    def isel(self, index) -> Coordinate: ...   # a slice or positions; an int drops it, so never called with one
    # optional: defining: bool = False; to_xarray() -> dict; from_xarray(dims, coords) -> Self | NoMatch

@dataclass(frozen=True)
class NoMatch:
    reason: str

# κ_d[π] for each indexed dim; the coordinate of an int-indexed dim is dropped
def isel_coords(coords: dict[str, Coordinate], indexers: dict[str, Any]) -> dict[str, Coordinate]: ...

# proposed (CP-D1), pipekit_array
@dataclass(frozen=True)
class Labels:
    dim: str
    values: tuple[Any, ...]

DimArray(data, dims, labels) keeps its constructor and its labels mapping; inside, each labelled dim holds a Labels.

Reuse

  • geoarray._src.coords.Coordinate (geotoolz-array 0.6.1): the four members to copy.
  • DimArrayAdapter (pipekit_array/named/_carrier.py): isel, rewrap, relabel switch to isel_coords.

References & Existing Code

  • Design: docs/design/coordax_carriers.md in jejjohnson/geostack (merged in jejjohnson/geostack#368), "Slicing commutes with coordinates" and pattern 1.
  • Prototype: q1_coordinates.py (Labels, generic_isel).

Implementation Steps

  • pipekit_ops/carriers/_coords.py with Coordinate, NoMatch, isel_coords; export from pipekit_ops.carriers.
  • Labels in pipekit_array/named/; DimArray and DimArrayAdapter use it.
  • Docs: the adapter page says how a coordinate type joins.

Definition of Done

  • Q1 oracle: pa.isel on DimArray gives the same data, dims and labels before and after for an int, a slice, a step slice, a list and two dims at once.
  • pipekit_array.testing adapter tests green; import pipekit_array loads neither JAX nor xarray.
  • jit traces of a DimArray unchanged (labels stay static).
  • Lint, type check and tests green.

Relationships

  • Parent: jejjohnson/geostack#369
  • Blocks: jejjohnson/gridax#627, jejjohnson/geotoolz#849, #407, #410
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.