scverse / scverse/scanpy

Remove inplace/copy

Open
#2,583 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Area – API
Dominant language
Python
Stars
2.6k
Forks
779
Avg merge
1d 4h
Merged PRs (30d)
27

Description

What kind of feature would you like to request?

Other?

Please describe your wishes

Another point that I'd like to throw into the scanpy 2.0 discussion:

Right now, many functions have the inplace argument, that determines if a function should write back to adata or return the result instead.

With this behavior it is hard to make correct type hints. While it is possible with @overload, it is cumbersome because it requires to type out the entire function signature twice. When I asked if it is possible to write these overloads in a more concise way on stackoverflow several users argued that changing the return type based on an argument is an anti-pattern, and I think they convinced me.

Alternative approach

Have two API levels, e.g.

def scanpy.tl.pca(adata: AnnData, **kwargs) -> None: ...

and

def scanpy.lowlevel.tl.pca(data: np.ndarray | sp.spmatrix, n_pcs) -> np.ndarray: ...

Where the former is a wrapper for the latter. This allows to separate the implementation of the actual method using only numpy/scipy data types from the scverse-specific behavior.

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

The proposal names scanpy.tl.pca and scanpy.lowlevel.tl.pca as example API entry points, with AnnData, NumPy, and SciPy data types. Start by reviewing how current functions use inplace and copy, then compare those usages with the proposed two-level API. Done requires an agreed migration design and scope; the issue names no files or tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
numpy, python
Domain
backend-api-design
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.