Declare supported types in the `use` type

Aperta
#4,579 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

Direzione di ricerca

Start by reading the accessor types and the array_support table in docs/conf.py (lines 171–213), then compare them with the type hints, runtime checks, and tests for functions such as tl.rank_genes_groups and umap. Define how supported array types should be represented in accessor annotations and how the docs should consume those declarations. Done means support declarations live with function types and the documentation reflects them consistently.

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

Descrizione

Triage 🩺
What kind of feature would you like to request?

Improved documentation or error message?

Please describe your wishes

Currently, which array types a function accepts is written down by hand in four places: the type hints, the array_support table in docs/conf.py, the array types each test picks, and a runtime check per function.

Apart from repeating code, these sometimes disagree. E.g., tl.rank_genes_groups runs on dask arrays and its test includes dask, but the conf.py table does not mention dask.

This gets more complicated with the recent accessoring, since use is typed as RepAcc which in turn translates to LayerAcc | MultiAcc. Thus, it is currently impossible to declare something like "this function only accepts accessors pointing to numpy or dask arrays" when following the established documentation patterns.

Instead of this, a few variants of RepAcc could provide the necessary documentation both in the code as well as for the docs directly. Example:

type RepInMemory = Annotated[LayerAcc | MultiAcc, ArraySupport("np", "sp")]
type RepLazy = Annotated[LayerAcc | MultiAcc, ArraySupport("np", "sp", "da", "xp")]
type RepGraphInMemory = Annotated[GraphAcc, ArraySupport("np", "sp")]

def umap(adata, *, use: RepGraphInMemory | str | None = None, rep: RepInMemory | str | None = None): ...

This would at least move the support declarations into the types of the functions and out of conf.py, which should make it easier for both humans and agents to see what is supported.

Nonetheless, this would not be enforcable on its own and would thus only be a first step. The next step might be to base runtime checks and test cases on this.

Ideally, it would be possible to declare the type an accessor would need to point to and have that be type-checked, but with the current accessor design in AnnData, I do not know how full typing could be implemented. So, the above would be my suggestion for now until full type checking becomes possible.

Please let me know if this is of interest and I can PR it.

Lingua principale
Python
Stelle
2.6k
Fork
809
Merge medio
1g 1h
PR unite (30g)
79

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 scverse/scanpy

Tutte le issue di scverse/scanpy

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.