Skip to content

Commit

Permalink
Import from utils
Browse files Browse the repository at this point in the history
  • Loading branch information
flying-sheep committed Jan 10, 2025
1 parent db3aa89 commit 120e4f8
Show file tree
Hide file tree
Showing 18 changed files with 25 additions and 51 deletions.
3 changes: 2 additions & 1 deletion src/scanpy/_utils/compute/is_constant.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@

from numpy.typing import NDArray

_CSMatrix = sparse.csr_matrix | sparse.csc_matrix
from ..._utils import _CSMatrix

_Array = NDArray | DaskArray | _CSMatrix

C = TypeVar("C", bound=Callable)
Expand Down
5 changes: 2 additions & 3 deletions src/scanpy/get/get.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
from anndata import AnnData
from numpy.typing import NDArray
from packaging.version import Version
from scipy.sparse import csc_matrix, csr_matrix

from .._utils import _CSMatrix

if TYPE_CHECKING:
from collections.abc import Collection, Iterable
Expand All @@ -21,8 +22,6 @@
from .._compat import DaskArray


_CSMatrix = csr_matrix | csc_matrix

# --------------------------------------------------------------------------------
# Plotting data helpers
# --------------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
if TYPE_CHECKING:
from typing import Literal

from scipy.sparse import csc_matrix, csr_matrix

_CSMatrix = csr_matrix | csc_matrix
from .._utils import _CSMatrix


@deprecated("Use sc.pp.highly_variable_genes instead")
Expand Down
4 changes: 1 addition & 3 deletions src/scanpy/preprocessing/_deprecated/sampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@
import numpy as np
from anndata import AnnData
from numpy.typing import NDArray
from scipy.sparse import csc_matrix, csr_matrix

from ..._compat import _LegacyRandom

_CSMatrix = csr_matrix | csc_matrix
from ..._utils import _CSMatrix


@old_positionals("n_obs", "random_state", "copy")
Expand Down
5 changes: 1 addition & 4 deletions src/scanpy/preprocessing/_pca/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,9 @@
import dask_ml.decomposition as dmld
import sklearn.decomposition as skld
from numpy.typing import DTypeLike, NDArray
from scipy import sparse

from ..._compat import _LegacyRandom
from ..._utils import Empty

_CSMatrix = sparse.csr_matrix | sparse.csc_matrix
from ..._utils import Empty, _CSMatrix

MethodDaskML = type[dmld.PCA | dmld.IncrementalPCA | dmld.TruncatedSVD]
MethodSklearn = type[skld.PCA | skld.TruncatedSVD]
Expand Down
4 changes: 1 addition & 3 deletions src/scanpy/preprocessing/_pca/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,10 @@
from typing import Literal

from numpy.typing import NDArray
from scipy import sparse
from sklearn.decomposition import PCA

from ..._compat import _LegacyRandom

_CSMatrix = sparse.csr_matrix | sparse.csc_matrix
from .._utils import _CSMatrix


def _pca_compat_sparse(
Expand Down
4 changes: 1 addition & 3 deletions src/scanpy/preprocessing/_pca/_dask_sparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@
from typing import Literal

from numpy.typing import DTypeLike
from scipy import sparse

from ..._compat import DaskArray

_CSMatrix = sparse.csr_matrix | sparse.csc_matrix
from .._utils import _CSMatrix


@dataclass
Expand Down
6 changes: 2 additions & 4 deletions src/scanpy/preprocessing/_qc.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
import numba
import numpy as np
import pandas as pd
from scipy.sparse import csc_matrix, csr_matrix, issparse, spmatrix
from scipy.sparse import csr_matrix, issparse, spmatrix

from scanpy.preprocessing._distributed import materialize_as_ndarray
from scanpy.preprocessing._utils import _get_mean_var

from .._compat import DaskArray, njit
from .._utils import _doc_params, axis_nnz, axis_sum
from .._utils import _CSMatrix, _doc_params, axis_nnz, axis_sum
from ._docs import (
doc_adata_basic,
doc_expr_reps,
Expand All @@ -28,8 +28,6 @@

from anndata import AnnData

_CSMatrix = csr_matrix | csc_matrix


def _choose_mtx_rep(adata, *, use_raw: bool = False, layer: str | None = None):
is_layer = layer is not None
Expand Down
3 changes: 1 addition & 2 deletions src/scanpy/preprocessing/_scale.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@

if TYPE_CHECKING:
from numpy.typing import NDArray
from scipy import sparse as sp

_CSMatrix = sp.csr_matrix | sp.csc_matrix
from .._utils import _CSMatrix


@njit
Expand Down
4 changes: 1 addition & 3 deletions src/scanpy/preprocessing/_scrublet/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,11 @@

from ..._compat import _LegacyRandom
from ...neighbors import _Metric, _MetricFn
from .._utils import _CSMatrix

__all__ = ["Scrublet"]


_CSMatrix = sparse.csr_matrix | sparse.csc_matrix


@dataclass(kw_only=True)
class Scrublet:
"""\
Expand Down
5 changes: 2 additions & 3 deletions src/scanpy/preprocessing/_scrublet/sparse_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@
if TYPE_CHECKING:
from numpy.typing import NDArray

from .._compat import _LegacyRandom

_CSMatrix = sparse.csr_matrix | sparse.csc_matrix
from ..._compat import _LegacyRandom
from ..._utils import _CSMatrix


def sparse_multiply(
Expand Down
3 changes: 1 addition & 2 deletions src/scanpy/preprocessing/_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from .._settings import settings as sett
from .._utils import (
_check_array_function_arguments,
_CSMatrix,
_resolve_axis,
axis_sum,
is_backed_type,
Expand Down Expand Up @@ -51,8 +52,6 @@
from .._utils import RNGLike, SeedLike


_CSMatrix = csr_matrix | csc_matrix

A = TypeVar("A", bound=np.ndarray | _CSMatrix | DaskArray)


Expand Down
5 changes: 1 addition & 4 deletions src/scanpy/preprocessing/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from sklearn.random_projection import sample_without_replacement

from .._compat import njit
from .._utils import axis_sum, elem_mul
from .._utils import _CSMatrix, axis_sum, elem_mul

if TYPE_CHECKING:
from typing import Literal
Expand All @@ -20,9 +20,6 @@
from .._utils import _SupportedArray


_CSMatrix = sparse.csr_matrix | sparse.csc_matrix


@singledispatch
def axis_mean(X: DaskArray, *, axis: Literal[0, 1], dtype: DTypeLike) -> DaskArray:
total = axis_sum(X, axis=axis, dtype=dtype)
Expand Down
3 changes: 1 addition & 2 deletions src/scanpy/tools/_leiden.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@
from typing import Literal

from anndata import AnnData
from scipy import sparse

from .._compat import _LegacyRandom
from .._utils import _CSMatrix

_CSMatrix = sparse.csr_matrix | sparse.csc_matrix

try:
from leidenalg.VertexPartition import MutableVertexPartition
Expand Down
4 changes: 1 addition & 3 deletions src/scanpy/tools/_louvain.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@
from typing import Any, Literal

from anndata import AnnData
from scipy.sparse import csc_matrix, csr_matrix

from .._compat import _LegacyRandom

_CSMatrix = csr_matrix | csc_matrix
from .._utils import _CSMatrix

try:
from louvain.VertexPartition import MutableVertexPartition
Expand Down
5 changes: 3 additions & 2 deletions src/scanpy/tools/_rank_genes_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@

from anndata import AnnData
from numpy.typing import NDArray
from scipy import sparse

from .._utils import _CSMatrix

_CorrMethod = Literal["benjamini-hochberg", "bonferroni"]
_CSMatrix = sparse.csr_matrix | sparse.csc_matrix


# Used with get_literal_vals
_Method = Literal["logreg", "t-test", "wilcoxon", "t-test_overestim_var"]
Expand Down
6 changes: 2 additions & 4 deletions src/scanpy/tools/_score_genes.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@
import pandas as pd
from scipy.sparse import issparse

from scanpy._utils import _check_use_raw, is_backed_type

from .. import logging as logg
from .._compat import old_positionals
from .._utils import _check_use_raw, is_backed_type
from ..get import _get_obs_rep

if TYPE_CHECKING:
Expand All @@ -20,15 +19,14 @@

from anndata import AnnData
from numpy.typing import DTypeLike, NDArray
from scipy.sparse import csc_matrix, csr_matrix

from .._compat import _LegacyRandom
from .._utils import _CSMatrix

try:
_StrIdx = pd.Index[str]
except TypeError: # Sphinx
_StrIdx = pd.Index
_CSMatrix = csr_matrix | csc_matrix
_GetSubset = Callable[[_StrIdx], np.ndarray | _CSMatrix]


Expand Down
3 changes: 1 addition & 2 deletions src/scanpy/tools/_utils_clustering.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@
import pandas as pd
from anndata import AnnData
from numpy.typing import NDArray
from scipy.sparse import csc_matrix, csr_matrix

_CSMatrix = csr_matrix | csc_matrix
from .._utils import _CSMatrix


def rename_groups(
Expand Down

0 comments on commit 120e4f8

Please sign in to comment.