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` diff --git a/src/scanpy/preprocessing/_simple.py b/src/scanpy/preprocessing/_simple.py index 986a2cd386..a9a675724a 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, order="C") X = _to_dense(X, order="C") if issparse(X) else X res = numpy_regress_out(X, regressors)