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

Use deprecation decorator #3380

Merged
merged 2 commits into from
Nov 22, 2024
Merged
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/3380.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Raise {exc}`FutureWarning` when calling deprecated {mod}`scanpy.pp` functions {smaller}`P Angerer`
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 @@
"fullname",
"pkg_metadata",
"pkg_version",
"old_positionals",
"deprecated",
"njit",
"_numba_threading_layer",
]


Expand Down Expand Up @@ -102,6 +106,15 @@
return lambda func: func


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

Check warning on line 110 in src/scanpy/_compat.py

View check run for this annotation

Codecov / codecov/patch

src/scanpy/_compat.py#L110

Added line #L110 was not covered by tests
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
Loading