Skip to content

Commit

Permalink
Deprecate log1p (#1067)
Browse files Browse the repository at this point in the history
* Deprecate `log1p` in favor of Scanpy's implementation

* Update unit tests relying on `log1p`

---------

Co-authored-by: michalk8 <46717574+michalk8@users.noreply.github.com>
  • Loading branch information
WeilerP and michalk8 committed May 31, 2023
1 parent ac5e374 commit f8e07ae
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
19 changes: 10 additions & 9 deletions scvelo/preprocessing/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
from scipy.sparse import issparse
from sklearn.utils import sparsefuncs

from anndata import AnnData

from scvelo import logging as logg
from scvelo.core import get_initial_size, get_size, multiply, set_initial_size, sum

Expand Down Expand Up @@ -587,14 +585,17 @@ def log1p(data, copy=False):
-------
Returns or updates `adata` depending on `copy`.
"""
adata = data.copy() if copy else data
X = (
(adata.X.data if issparse(adata.X) else adata.X)
if isinstance(adata, AnnData)
else adata
warnings.warn(
"`log1p` is deprecated since scVelo v0.3.0 and will be removed in a "
"future version. Please use `log1p` from `scanpy.pp` instead.",
DeprecationWarning,
stacklevel=2,
)
np.log1p(X, out=X)
return adata if copy else None

from scanpy.pp import log1p as scanpy_log1p

res = scanpy_log1p(data, copy=copy)
return res if copy else None


def filter_and_normalize(
Expand Down
4 changes: 2 additions & 2 deletions tests/preprocessing/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2321,7 +2321,7 @@ def test_pancreas50obs(self, capfd, pancreas_50obs):
)
)
assert pancreas_50obs.var.columns.equals(pd.Index(["gene_count_corr"]))
assert [*pancreas_50obs.uns] == ["pca", "neighbors"]
assert [*pancreas_50obs.uns] == ["log1p", "pca", "neighbors"]
assert [*pancreas_50obs.obsm] == ["X_pca"]
assert [*pancreas_50obs.varm] == ["PCs"]
assert [*pancreas_50obs.layers] == ["spliced", "unspliced", "Ms", "Mu"]
Expand Down Expand Up @@ -2373,7 +2373,7 @@ def test_dentategyrus50obs(self, capfd, dentategyrus_50obs):
)
)
assert dentategyrus_50obs.var.columns.equals(pd.Index([]))
assert [*dentategyrus_50obs.uns] == ["pca", "neighbors"]
assert [*dentategyrus_50obs.uns] == ["log1p", "pca", "neighbors"]
assert [*dentategyrus_50obs.obsm] == ["X_pca"]
assert [*dentategyrus_50obs.varm] == ["PCs"]
assert [*dentategyrus_50obs.layers] == [
Expand Down

0 comments on commit f8e07ae

Please sign in to comment.