Skip to content

Consolidate typing for coords #7972

@williambdean

Description

@williambdean

coords have a mix of types in the codebase. Some places:

coords=None,

The conversion type:

pymc/pymc/model/core.py

Lines 911 to 914 in 4ad7fa8

@property
def coords(self) -> dict[str, tuple | None]:
"""Coordinate values for model dimensions."""
return self._coords

values: Sequence | np.ndarray,

def coords_and_dims_for_inferencedata(model: Model) -> tuple[dict[str, Any], dict[str, Any]]:

Seems to be a mix of Sequence and Sequence | np.ndarray so some
consolidation would be nice. For example, there is already a various amount of
typing for other objects like dims and shape:

# User-provided can be lazily specified as scalars
Shape: TypeAlias = int | TensorVariable | Sequence[int | Variable]
Dims: TypeAlias = str | Sequence[str | None]
DimsWithEllipsis: TypeAlias = str | EllipsisType | Sequence[str | None | EllipsisType]
Size: TypeAlias = int | TensorVariable | Sequence[int | Variable]
# After conversion to vectors
StrongShape: TypeAlias = TensorVariable | tuple[int | Variable, ...]
StrongDims: TypeAlias = Sequence[str]
StrongDimsWithEllipsis: TypeAlias = Sequence[str | EllipsisType]
StrongSize: TypeAlias = TensorVariable | tuple[int | Variable, ...]

My main concern is not within pymc package directly but in the downstream
usage where using dict[str, Any] is probably the most common way to type
coords. So exposing would have some typing benefit.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions