Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Shared sparse one-hot (indicator) helper for squidpy and scanpy

Open
#224 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
72/100
Issue type
Refactor
Clarity
Clearly specified
Activity status
Active
Tech stack
numpy, python
Domain
tooling

Research direction

Start with scanpy/get/_aggregated.py and squidpy/gr/_nhood.py, then review the proposed fast_array_utils.conv entry point and its sparse extra. Confirm the shared helper preserves missing labels, unused categories, mask handling, float64 output, and the stated matrix layouts; done means both callers use it without changing their current behavior.

Written by the indexing model from the issue text.

Description

prettified with ai, basically saying we have two different functions we can unify here. low prio but good to document.

scanpy (sparse_indicator in scanpy/get/_aggregated.py) and squidpy (_onehot in squidpy/gr/_nhood.py) each keep a private helper that turns category codes into a sparse float64 indicator matrix, with a missing label (-1) giving no entry. They differ only in interface: scanpy takes a pd.Categorical and returns (n_categories, n_obs) as a coo_array with an optional mask, while squidpy takes a pd.Series and returns a (n_obs, n_categories) csr_matrix.

Proposal for fast_array_utils.conv (needs the sparse extra; takes codes since fast-array-utils doesn't depend on pandas):

def sparse_indicator(
    codes: NDArray[np.integer], n_categories: int, *, mask: NDArray[np.bool] | None = None
) -> coo_array:
    keep = codes >= 0 if mask is None else (codes >= 0) & mask
    obs = np.flatnonzero(keep)
    return coo_array((np.ones(obs.size), (obs, codes[keep])), shape=(codes.size, n_categories))
  • (n_obs, n_categories), the usual one-hot layout; scanpy takes .T (about 3 ms at 5M observations).
  • float64, as both callers use today.
  • Same cost as both copies today: squidpy converts the result to CSR, as it does now.

checked with missing labels, unused categories and mask.

as discussed in squidpy/#1285

Dominant language
Python
Stars
15
Forks
5
Avg merge
14h 52m
Merged PRs (30d)
13

Getting set up

We have not checked this project's setup files yet. Start from its README, and see our first-contribution guide for the general steps.

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 scverse/fast-array-utils

All issues in scverse/fast-array-utils

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.