scverse / scverse/squidpy

Public api change: rename adata to data and make it positional only

Open
#1,180 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
598
Forks
121
Avg merge
3d 11h
Merged PRs (30d)
3

Description

Makes sense to me! Make sure to add a / to the parameter specification to enforce that people aren’t actually using the name.

And put the / after all the “main” parameters if there are more than just data. Depends on your judgement what a “main” parameters are – it’s often the same list as the mandatory parameters, unless a function has too many mandatory parameters, or multiple mandatory parameters have the same type and the order could be confusing.

I think most good APIs have 1–2 positional-only parameters (might have defaults), and some keyword-only parameters that all have defaults. Most functions have zero positional-or-keyword parameters, but for some it makes sense.

e.g. var_by_distance would look like this:

def var_by_distance(
    adata: AnnData,
    groups: str | list[str] | NDArrayA,
    /,
    *,
    cluster_key: str | None = None,
    ...
) -> ...:

whereas nhood_enrichment would look like this, so people can call it either as nhood_enrichment(adata, "k") or nhood_enrichment(adata, cluster_key=..., library_key=...) to clarify which key is which.

def nhood_enrichment(
    data: AnnData | SpatialData,
    /,
    cluster_key: str,
    *,
    library_key: str | None = None,
    connectivity_key: str | None = None,
    ...
) -> ...:

Originally posted by @flying-sheep in https://github.com/scverse/squidpy/issues/1134#issuecomment-4458065013

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.

Research direction

Start by searching the Python source for public functions using adata, beginning with the var_by_distance and nhood_enrichment examples named in the issue. Review which parameters are main versus keyword-only, then consider the work complete when the affected public signatures consistently use positional-only data as specified.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api, backend-api-design
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.