Skip to content

match scanpy data vs adata#699

Merged
Intron7 merged 3 commits into
mainfrom
mirror-data-vs-adata
Jun 26, 2026
Merged

match scanpy data vs adata#699
Intron7 merged 3 commits into
mainfrom
mirror-data-vs-adata

Conversation

@Intron7

@Intron7 Intron7 commented Jun 26, 2026

Copy link
Copy Markdown
Member

scanpy has some function where the function sig uses data and not adata. this PR adresses this

Signed-off-by: Intron7 <severin.dicks@icloud.com>
@Intron7

Intron7 commented Jun 26, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 26, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai

coderabbitai Bot commented Jun 26, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Summary by CodeRabbit

  • New Features

    • Preprocessing functions now support both full AnnData inputs and direct matrix inputs in more places.
    • Added a new square-root transformation option for data matrices.
  • Bug Fixes

    • Improved consistency of scaling, normalization, and PCA results when using array inputs.
    • Updated handling of output placement and metadata when operating on AnnData objects.

Walkthrough

Normalization, PCA, and scaling preprocessing functions now accept either AnnData or matrix inputs. sqrt is added to preprocessing exports, and the release notes and tests are updated for the new behavior.

Changes

Preprocessing API updates

Layer / File(s) Summary
Normalization surface and sqrt addition
docs/release-notes/0.16.0.md, src/rapids_singlecell/preprocessing/__init__.py, src/rapids_singlecell/preprocessing/_normalize.py, tests/test_normalization.py
log1p now accepts AnnData or matrix input through data, sqrt is added and exported, and normalization tests cover both input paths.
PCA matrix input path
src/rapids_singlecell/preprocessing/_pca.py, tests/test_pca.py
pca now accepts AnnData or matrix input, resolves mask_var for arrays, and returns the PCA embedding for non-AnnData inputs.
Scaling matrix input path
src/rapids_singlecell/preprocessing/_scale.py, tests/test_scaling.py
scale now accepts AnnData or matrix input, dispatches by array type, and returns the scaled matrix for non-AnnData inputs.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • scverse/rapids-singlecell#626: Updates the pca mask-resolution path in the same preprocessing module and is directly related to the new array-input branching here.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 47.06% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title is directly related to the main change: aligning Scanpy-style data versus adata naming.
Description check ✅ Passed The description is related to the changeset and states the intent to address Scanpy's data-vs-adata signature mismatch.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch mirror-data-vs-adata

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/rapids_singlecell/preprocessing/_pca.py`:
- Around line 220-241: The non-AnnData branch in the PCA routine now returns the
computed embedding, so the public API contract is outdated. Update the return
annotation for the function containing the `if not isinstance(data, AnnData)`
path and `_pca_compute` call so it includes the array result (`X_pca`) instead
of only `None | AnnData`, keeping the signature aligned with the actual return
behavior for type checkers and stubs.
- Around line 297-313: The _resolve_mask_var_array helper currently validates
only the mask shape, so non-boolean arrays can slip through and be treated as
positional indices instead of masks. Update this function to require a boolean
dtype (or safely coerce and then validate it remains boolean) before returning
the array, and raise a ValueError for any non-boolean mask_var input. Keep the
existing shape check in _resolve_mask_var_array so X[:, mask_var] is only ever
used with a true boolean mask.

In `@src/rapids_singlecell/preprocessing/_scale.py`:
- Around line 83-101: The matrix path in the scaling logic currently only blocks
string mask_obs values, so ndarray-like masks can still reach _scale_dispatch
and be misused for row selection and CUDA masking. In the non-AnnData branch of
the scaling function, add validation for mask_obs before assigning X and
dispatching, using the existing _check_gpu_X / _scale_dispatch flow to reject
non-boolean or wrong-length masks early with a clear ValueError. Keep the check
alongside the current AnnData-only validation so the behavior is enforced before
any scaling work begins.

In `@tests/test_normalization.py`:
- Around line 151-157: The normalization tests are still using CuPy math to
build the expected values, so the new matrix-input path is not being validated
against a CPU reference. Update the assertions in the affected normalization
test cases to compare the computed result via cp.asnumpy(...) against
NumPy/SciPy host-side expected values instead of using cp.log1p or cp.sqrt for
the reference. Keep the existing test structure, but move the reference
construction to CPU-backed arrays and use the same assertion helpers to validate
numerical correctness.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 0500e958-05f4-4cdf-bbba-6d28b116e3b3

📥 Commits

Reviewing files that changed from the base of the PR and between af2d99f and b12e2d8.

📒 Files selected for processing (8)
  • docs/release-notes/0.16.0.md
  • src/rapids_singlecell/preprocessing/__init__.py
  • src/rapids_singlecell/preprocessing/_normalize.py
  • src/rapids_singlecell/preprocessing/_pca.py
  • src/rapids_singlecell/preprocessing/_scale.py
  • tests/test_normalization.py
  • tests/test_pca.py
  • tests/test_scaling.py

Comment thread src/rapids_singlecell/preprocessing/_pca.py
Comment thread src/rapids_singlecell/preprocessing/_pca.py Outdated
Comment thread src/rapids_singlecell/preprocessing/_scale.py
Comment thread tests/test_normalization.py Outdated
@codecov-commenter

codecov-commenter commented Jun 26, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 84.00000% with 16 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.31%. Comparing base (af2d99f) to head (5d8ac09).

Files with missing lines Patch % Lines
src/rapids_singlecell/preprocessing/_normalize.py 75.00% 10 Missing ⚠️
src/rapids_singlecell/preprocessing/_scale.py 84.61% 4 Missing ⚠️
src/rapids_singlecell/preprocessing/_pca.py 93.10% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #699      +/-   ##
==========================================
- Coverage   90.39%   90.31%   -0.09%     
==========================================
  Files         104      104              
  Lines        9507     9570      +63     
==========================================
+ Hits         8594     8643      +49     
- Misses        913      927      +14     
Files with missing lines Coverage Δ
src/rapids_singlecell/preprocessing/__init__.py 100.00% <100.00%> (ø)
src/rapids_singlecell/preprocessing/_simple.py 79.01% <100.00%> (ø)
src/rapids_singlecell/preprocessing/_pca.py 95.62% <93.10%> (-1.00%) ⬇️
src/rapids_singlecell/preprocessing/_scale.py 91.61% <84.61%> (-0.70%) ⬇️
src/rapids_singlecell/preprocessing/_normalize.py 89.03% <75.00%> (-2.99%) ⬇️

Signed-off-by: Intron7 <severin.dicks@icloud.com>
@Intron7 Intron7 enabled auto-merge (squash) June 26, 2026 17:09
@Intron7 Intron7 disabled auto-merge June 26, 2026 17:25
Signed-off-by: Intron7 <severin.dicks@icloud.com>
@Intron7 Intron7 merged commit 8840275 into main Jun 26, 2026
23 of 26 checks passed
@Intron7 Intron7 deleted the mirror-data-vs-adata branch June 26, 2026 18:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants