From 95da48d33e6590cf0db36fbd3b56f5518a14f275 Mon Sep 17 00:00:00 2001 From: Intron7 Date: Tue, 11 Feb 2025 13:29:07 +0100 Subject: [PATCH 1/3] fix int for shortcut --- src/scanpy/preprocessing/_simple.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/scanpy/preprocessing/_simple.py b/src/scanpy/preprocessing/_simple.py index 986a2cd386..6468926602 100644 --- a/src/scanpy/preprocessing/_simple.py +++ b/src/scanpy/preprocessing/_simple.py @@ -752,6 +752,9 @@ def regress_out( # 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) X = _to_dense(X, order="C") if issparse(X) else X res = numpy_regress_out(X, regressors) From fb98956c69319e241e14838a4431bfc61062d908 Mon Sep 17 00:00:00 2001 From: Intron7 Date: Tue, 11 Feb 2025 13:36:50 +0100 Subject: [PATCH 2/3] add release note --- docs/release-notes/3461.bugfix.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 docs/release-notes/3461.bugfix.md diff --git a/docs/release-notes/3461.bugfix.md b/docs/release-notes/3461.bugfix.md new file mode 100644 index 0000000000..8635c319cf --- /dev/null +++ b/docs/release-notes/3461.bugfix.md @@ -0,0 +1 @@ +Fixes an error where `regress_out` would fail to work with `integer` types {smaller}`S Dicks` From 1abe26c4108638a023243362af07effdc97583b4 Mon Sep 17 00:00:00 2001 From: Intron7 Date: Tue, 11 Feb 2025 14:30:24 +0100 Subject: [PATCH 3/3] add order to astype --- src/scanpy/preprocessing/_simple.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/scanpy/preprocessing/_simple.py b/src/scanpy/preprocessing/_simple.py index 6468926602..a9a675724a 100644 --- a/src/scanpy/preprocessing/_simple.py +++ b/src/scanpy/preprocessing/_simple.py @@ -754,7 +754,7 @@ def 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) + X = X.astype(target_dtype, order="C") X = _to_dense(X, order="C") if issparse(X) else X res = numpy_regress_out(X, regressors)