match scanpy data vs adata#699
Conversation
Signed-off-by: Intron7 <severin.dicks@icloud.com>
|
@coderabbitai review |
✅ Action performedReview finished.
|
📝 WalkthroughSummary by CodeRabbit
WalkthroughNormalization, PCA, and scaling preprocessing functions now accept either ChangesPreprocessing API updates
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (8)
docs/release-notes/0.16.0.mdsrc/rapids_singlecell/preprocessing/__init__.pysrc/rapids_singlecell/preprocessing/_normalize.pysrc/rapids_singlecell/preprocessing/_pca.pysrc/rapids_singlecell/preprocessing/_scale.pytests/test_normalization.pytests/test_pca.pytests/test_scaling.py
Codecov Report❌ Patch coverage is 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
|
Signed-off-by: Intron7 <severin.dicks@icloud.com>
Signed-off-by: Intron7 <severin.dicks@icloud.com>
scanpy has some function where the function sig uses data and not adata. this PR adresses this