Skip to content

Remove inplace argument in scanpy 2.0 #2583

@grst

Description

@grst

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    Status

    Meta

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions