Skip to content

Commit

Permalink
Use deprecation decorator
Browse files Browse the repository at this point in the history
  • Loading branch information
flying-sheep committed Nov 21, 2024
1 parent 751eafa commit f11b6ba
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 23 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ dependencies = [
"packaging>=21.3",
"session-info",
"legacy-api-wrap>=1.4", # for positional API deprecations
"typing-extensions; python_version < '3.13'",
]
dynamic = ["version"]

Expand Down
13 changes: 13 additions & 0 deletions src/scanpy/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ class ZappyArray:
"fullname",
"pkg_metadata",
"pkg_version",
"old_positionals",
"deprecated",
"njit",
"_numba_threading_layer",
]


Expand Down Expand Up @@ -102,6 +106,15 @@ def old_positionals(*old_positionals: str):
return lambda func: func


if sys.version_info >= (3, 13):
from warnings import deprecated as _deprecated
else:
from typing_extensions import deprecated as _deprecated


deprecated = partial(_deprecated, category=FutureWarning)


@overload
def njit(fn: Callable[P, R], /) -> Callable[P, R]: ...
@overload
Expand Down
3 changes: 2 additions & 1 deletion src/scanpy/plotting/_preprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from matplotlib import pyplot as plt
from matplotlib import rcParams

from .._compat import old_positionals
from .._compat import deprecated, old_positionals
from .._settings import settings
from . import _utils

Expand Down Expand Up @@ -103,6 +103,7 @@ def highly_variable_genes(


# backwards compat
@deprecated("Use sc.pl.highly_variable_genes instead")
@old_positionals("log", "show", "save")
def filter_genes_dispersion(
result: np.recarray,
Expand Down
24 changes: 12 additions & 12 deletions src/scanpy/preprocessing/_deprecated/highly_variable_genes.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from scipy.sparse import issparse

from ... import logging as logg
from ..._compat import old_positionals
from ..._compat import deprecated, old_positionals
from .._distributed import materialize_as_ndarray
from .._utils import _get_mean_var

Expand All @@ -19,6 +19,7 @@
from scipy.sparse import spmatrix


@deprecated("Use sc.pp.highly_variable_genes instead")
@old_positionals(
"flavor",
"min_disp",
Expand Down Expand Up @@ -48,18 +49,17 @@ def filter_genes_dispersion(
"""\
Extract highly variable genes :cite:p:`Satija2015,Zheng2017`.
.. warning::
.. deprecated:: 1.3.6
Use :func:`~scanpy.pp.highly_variable_genes`
instead. The new function is equivalent to the present
function, except that
.. deprecated:: 1.3.6
* the new function always expects logarithmized data
* `subset=False` in the new function, it suffices to
merely annotate the genes, tools like `pp.pca` will
detect the annotation
* you can now call: `sc.pl.highly_variable_genes(adata)`
* `copy` is replaced by `inplace`
Use :func:`~scanpy.pp.highly_variable_genes` instead.
The new function is equivalent to the present function, except that
* the new function always expects logarithmized data
* `subset=False` in the new function, it suffices to
merely annotate the genes, tools like `pp.pca` will
detect the annotation
* you can now call: `sc.pl.highly_variable_genes(adata)`
* `copy` is replaced by `inplace`
If trying out parameters, pass the data matrix instead of AnnData.
Expand Down
21 changes: 11 additions & 10 deletions src/scanpy/preprocessing/_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from sklearn.utils import check_array, sparsefuncs

from .. import logging as logg
from .._compat import njit, old_positionals
from .._compat import deprecated, njit, old_positionals
from .._settings import settings as sett
from .._utils import (
_check_array_function_arguments,
Expand Down Expand Up @@ -474,6 +474,7 @@ def sqrt(
return X.sqrt()


@deprecated("Use sc.pp.normalize_total instead")
@old_positionals(
"counts_per_cell_after",
"counts_per_cell",
Expand All @@ -497,16 +498,16 @@ def normalize_per_cell(
"""\
Normalize total counts per cell.
.. warning::
.. deprecated:: 1.3.7
Use :func:`~scanpy.pp.normalize_total` instead.
The new function is equivalent to the present
function, except that
.. deprecated:: 1.3.7
* the new function doesn't filter cells based on `min_counts`,
use :func:`~scanpy.pp.filter_cells` if filtering is needed.
* some arguments were renamed
* `copy` is replaced by `inplace`
Use :func:`~scanpy.pp.normalize_total` instead.
The new function is equivalent to the present
function, except that
* the new function doesn't filter cells based on `min_counts`,
use :func:`~scanpy.pp.filter_cells` if filtering is needed.
* some arguments were renamed
* `copy` is replaced by `inplace`
Normalize each cell by total counts over all genes, so that every cell has
the same total count after normalization.
Expand Down

0 comments on commit f11b6ba

Please sign in to comment.