Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix int for shortcut #3461

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/release-notes/3461.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixes an error where `regress_out` would fail to work with `integer` types {smaller}`S Dicks`
3 changes: 3 additions & 0 deletions src/scanpy/preprocessing/_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,9 @@
# if the regressors are not categorical and the matrix is not singular
# use the shortcut numpy_regress_out
if not variable_is_categorical and np.linalg.det(regressors.T @ regressors) != 0:
if np.issubdtype(X.dtype, np.integer):
target_dtype = np.float32 if X.dtype.itemsize <= 4 else np.float64
X = X.astype(target_dtype, order="C")

Check warning on line 757 in src/scanpy/preprocessing/_simple.py

View check run for this annotation

Codecov / codecov/patch

src/scanpy/preprocessing/_simple.py#L756-L757

Added lines #L756 - L757 were not covered by tests
Copy link
Contributor

Choose a reason for hiding this comment

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

But this could also apply to sparse? And we don't want the argument then, no? https://docs.scipy.org/doc/scipy/reference/generated/scipy.sparse.csr_matrix.astype.html nothing here about order

X = _to_dense(X, order="C") if issparse(X) else X
res = numpy_regress_out(X, regressors)

Expand Down