You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
e.g pp.filter_genes_dispersion returns a dict with known keys. if you know the keys, this means you should return an object where you can use attribute access instead. usually the pythonic thing to do in this case is to return a namedtuple.
funnily we haven’t quite fixed this: normalize_total still returns a dict. Can be fixed like this maybe:
from __future__ importannotationsfromcollections.abcimportMappingfromdataclassesimportfields, is_dataclassfromtypingimportTYPE_CHECKINGfromscverse_miscimportDeprecation, deprecatedifTYPE_CHECKING:
fromcollections.abcimportIteratorfromtypingimportFinal__all__= ["DeprecatedMapping"]
MSG: Final=Deprecation(
"1.13.0",
"Indexing this result like a `dict` is deprecated. Access its attributes instead.",
)
classDeprecatedMapping[V](Mapping[str, V]):
"""`Mapping` interface over a dataclass’ fields, for types that used to be `dict`s."""@deprecated(MSG)def__getitem__(self, key: str) ->V:
assertis_dataclass(self)
ifkeynotin (names:= [f.nameforfinfields(self)]):
msg=f"{key!r}, expected one of {names}"raiseKeyError(msg)
returngetattr(self, key)
@deprecated(MSG)def__iter__(self) ->Iterator[str]:
assertis_dataclass(self)
return (f.nameforfinfields(self))
@deprecated(MSG)def__len__(self) ->int:
assertis_dataclass(self)
returnlen(fields(self))
fromdataclassesimportdataclassfromtypingimportTYPE_CHECKINGfrom .._utilsimportDeprecatedMappingifTYPE_CHECKING:
importnumpyasnpfrom .._compatimportCSBase, DaskArray@dataclass(frozen=True)classNormalizedTotal(DeprecatedMapping["np.ndarray | CSBase | DaskArray"]):
"""Result of :func:`~scanpy.pp.normalize_total`."""X: np.ndarray|CSBase|DaskArray"""The normalized matrix."""norm_factor: np.ndarray|DaskArray"""Counts per cell before normalization."""
Activity
flying-sheep commentedon Sep 11, 2026
funnily we haven’t quite fixed this:
normalize_totalstill returns a dict. Can be fixed like this maybe: