fix: ensure read_10x_mtx returns CSR format#4017
Open
ernestprovo23 wants to merge 1 commit intoscverse:mainfrom
Open
fix: ensure read_10x_mtx returns CSR format#4017ernestprovo23 wants to merge 1 commit intoscverse:mainfrom
ernestprovo23 wants to merge 1 commit intoscverse:mainfrom
Conversation
Transposing a CSR matrix in scipy produces CSC format. Add explicit tocsr() conversion after the .T transpose in _read_10x_mtx() and add a format assertion to the test suite. Fixes scverse#4016
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4017 +/- ##
=======================================
Coverage 78.34% 78.34%
=======================================
Files 117 117
Lines 12782 12783 +1
=======================================
+ Hits 10014 10015 +1
Misses 2768 2768
Flags with carried forward coverage won't be shown. Click here to find out more.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Ensure
read_10x_mtx()returns an AnnData object with a CSR sparse matrix instead of CSC.Motivation
Fixes #4016
When
_read_10x_mtx()transposes the matrix read byanndata.read_mtx(), scipy automatically converts the CSR matrix to CSC format (this is how scipy sparse transpose works — CSR.T → CSC). Most downstream scanpy operations expect CSR format.Changes
adata.X = adata.X.tocsr()after the.Ttranspose in_read_10x_mtx()(src/scanpy/readwrite.py)test_read_10x(tests/test_read_10x.py)Testing
test_read_10xparametrized cases pass locally (v1.2.0 + v3.0.0, with and without prefix)Notes for reviewers