Consolidate typing for `coords`

Open
#7,972 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
45/100
Issue type
Refactor
Clarity
Mostly clear
Activity status
Stale
Tech stack
numpy, python

Research direction

Start by comparing the coords annotations and conversions in pymc/model/core.py and pymc/backends/arviz.py with the existing dims and shape typing in pymc/distributions/shape_utils.py. Consolidate the coords type across the cited locations and expose a consistent annotation that improves downstream typing without relying on dict[str, Any].

Written by the indexing model from the issue text.

Description

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

https://github.com/pymc-devs/pymc/blob/4ad7fa8f88525fae096886fb7a7b19247a7c5176/pymc/model/core.py?plain=1#L458

The conversion type:

https://github.com/pymc-devs/pymc/blob/4ad7fa8f88525fae096886fb7a7b19247a7c5176/pymc/model/core.py?plain=1#L911-L914

https://github.com/pymc-devs/pymc/blob/4ad7fa8f88525fae096886fb7a7b19247a7c5176/pymc/model/core.py?plain=1#L1065

https://github.com/pymc-devs/pymc/blob/4ad7fa8f88525fae096886fb7a7b19247a7c5176/pymc/backends/arviz.py?plain=1#L126

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:

https://github.com/pymc-devs/pymc/blob/4ad7fa8f88525fae096886fb7a7b19247a7c5176/pymc/distributions/shape_utils.py?plain=1#L88-L98

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.

Dominant language
Python
Stars
9.8k
Forks
2.3k
Avg merge
21h 39m
Merged PRs (30d)
5

Contributor guide

Open the contributing guide

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 pymc-devs/pymc

All issues in pymc-devs/pymc

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.