diff --git a/CHANGELOG.md b/CHANGELOG.md index ee67fbe..0ffa566 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,11 @@ and this project adheres to [Semantic Versioning][]. - `update()`, `push_obs()`, `push_var()`, `pull_obs()`, and `pull_var()` now try harder to preserve the dtype of the dataframe columns +### Deprecated + +- `MuData.mod_names`, `MuData.obs_keys`, `MuData.var_keys`, `MuData.obsm_keys`, `MuData.varm_keys`, `MuData.uns_keys`, `MuData.obs_vector`, `MuData.var_vector`. + Their analogs in AnnData will be deprecated in AnnData 0.13. + ## [0.3.3] ### Fixed diff --git a/pyproject.toml b/pyproject.toml index 673c277..0c6f694 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -34,7 +34,7 @@ dependencies = [ "numpy", "pandas>=1.4", "scipy", - "scverse-misc", + "scverse-misc>=0.0.3", # for debug logging (referenced from the issue template) "session-info2", ] diff --git a/src/mudata/_core/mudata.py b/src/mudata/_core/mudata.py index a1edf1d..61aa398 100644 --- a/src/mudata/_core/mudata.py +++ b/src/mudata/_core/mudata.py @@ -20,6 +20,7 @@ from anndata._core.aligned_mapping import AxisArraysBase from anndata._core.views import DataFrameView from anndata.utils import convert_to_dict +from scverse_misc import Deprecation, deprecated from .compat import AlignedView, AxisArrays, PairwiseArrays from .config import OPTIONS @@ -1248,6 +1249,7 @@ def _attr_vector(self, key: str, attr: str) -> np.ndarray: raise KeyError(f"There is no key {key} in MuData .{attr} or in .{attr} of any modalities.") return df[key].to_numpy() + @deprecated(Deprecation("0.3.4")) def obs_vector(self, key: str, layer: str | None = None) -> np.ndarray: """Return an array of values for the requested key of length n_obs. @@ -1391,6 +1393,7 @@ def n_var(self) -> int: # ) return self._var.shape[0] + @deprecated(Deprecation("0.3.4")) def var_vector(self, key: str, layer: str | None = None) -> np.ndarray: """Return an array of values for the requested key of length n_var. @@ -1558,22 +1561,27 @@ def uns(self): # _keys methods to increase compatibility # with calls requiring those AnnData methods + @deprecated(Deprecation("0.3.4", msg="Use `obs.columns` instead.")) def obs_keys(self) -> list[str]: """List keys of observation annotation :attr:`obs`.""" return self._obs.keys().tolist() + @deprecated(Deprecation("0.3.4", msg="Use `var.columns` instead.")) def var_keys(self) -> list[str]: """List keys of variable annotation :attr:`var`.""" return self._var.keys().tolist() + @deprecated(Deprecation("0.3.4", msg="Use `obsm.keys()` instead.")) def obsm_keys(self) -> list[str]: """List keys of observation annotation :attr:`obsm`.""" return list(self._obsm.keys()) + @deprecated(Deprecation("0.3.4", msg="Use `varm.keys()` instead.")) def varm_keys(self) -> list[str]: """List keys of variable annotation :attr:`varm`.""" return list(self._varm.keys()) + @deprecated(Deprecation("0.3.4", msg="Use `uns.keys()` instead.")) def uns_keys(self) -> list[str]: """List keys of unstructured annotation.""" return list(self._uns.keys()) @@ -1599,6 +1607,7 @@ def axis(self) -> Literal[-1, 0, 1]: return self._axis @property + @deprecated(Deprecation("0.3.4", msg="Use `mod.keys()` instead.")) def mod_names(self) -> list[str]: """Names of modalities (alias for `list(mdata.mod.keys())`)""" return list(self._mod.keys()) diff --git a/src/mudata/_core/utils.py b/src/mudata/_core/utils.py index f4ef8cf..29df25d 100644 --- a/src/mudata/_core/utils.py +++ b/src/mudata/_core/utils.py @@ -1,12 +1,14 @@ +from __future__ import annotations + from collections import Counter -from collections.abc import Mapping, Sequence from contextlib import suppress -from typing import Literal, TypeVar +from typing import TYPE_CHECKING, Literal import numpy as np import pandas as pd -T = TypeVar("T", pd.Series, pd.DataFrame) +if TYPE_CHECKING: + from collections.abc import Mapping, Sequence def _make_index_unique(df: pd.DataFrame, force: bool = False) -> pd.DataFrame: