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
Describe the bug
With the new anndata 0.10.9 release, anndata no longer allows pandas DataFrames to be stored in varm and throws an error when doing so (see 3rd bullet point of release notes here). When refitting a Deseq model (e.g., by running dds.deseq2 where dds = DeseqDataSet with refit_cooks=True) and no sample can be replaced, a pandas.Series is stored in adata.varm, resulting in a ValueError. I believe this issue can be fixed by storing the data differently, for example, as a binary (0/1) in a numpy array.
Desktop (please complete the following information):
OS: I verified that the bug exists on Ubuntu and MacOS
Error Traceback
test_compare_groups.py:19:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
../../../pertpy/tools/_differential_gene_expression/_base.py:513: in compare_groups
model.fit(**fit_kwargs)
../../../pertpy/tools/_differential_gene_expression/_pydeseq2.py:59: in fit
dds.deseq2()
/opt/homebrew/Caskroom/mambaforge/base/envs/py12-pertpy-env/lib/python3.12/site-packages/pydeseq2/dds.py:501: in deseq2
self.refit()
/opt/homebrew/Caskroom/mambaforge/base/envs/py12-pertpy-env/lib/python3.12/site-packages/pydeseq2/dds.py:938: in refit
self._replace_outliers()
/opt/homebrew/Caskroom/mambaforge/base/envs/py12-pertpy-env/lib/python3.12/site-packages/pydeseq2/dds.py:1128: in _replace_outliers
self.varm["replaced"] = pd.Series(False, index=self.var_names)
/opt/homebrew/Caskroom/mambaforge/base/envs/py12-pertpy-env/lib/python3.12/site-packages/anndata/_core/aligned_mapping.py:216: in __setitem__
value = self._validate_value(value, key)
/opt/homebrew/Caskroom/mambaforge/base/envs/py12-pertpy-env/lib/python3.12/site-packages/anndata/_core/aligned_mapping.py:279: in _validate_value
return super()._validate_value(val, key)
/opt/homebrew/Caskroom/mambaforge/base/envs/py12-pertpy-env/lib/python3.12/site-packages/anndata/_core/aligned_mapping.py:100: in _validate_value
return coerce_array(val, name=name, allow_df=self._allow_df)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
value = gene1 False
gene2 False
dtype: bool
def coerce_array(
value: Any,
*,
name: str,
allow_df: bool = False,
allow_array_like: bool = False,
):
"""Coerce arrays stored in layers/X, and aligned arrays ({obs,var}{m,p})."""
# If value is a scalar and we allow that, return it
if allow_array_like and np.isscalar(value):
return value
# If value is one of the allowed types, return it
if isinstance(value, ArrayDataStructureType.classes()):
if isinstance(value, np.matrix):
msg = f"{name} should not be a np.matrix, use np.ndarray instead."
warnings.warn(msg, ImplicitModificationWarning)
value = value.A
return value
if isinstance(value, pd.DataFrame):
if allow_df:
raise_value_error_if_multiindex_columns(value, name)
return value if allow_df else ensure_df_homogeneous(value, name)
# if value is an array-like object, try to convert it
e = None
if allow_array_like:
try:
# TODO: asarray? asanyarray?
return np.array(value)
except (ValueError, TypeError) as _e:
e = _e
# if value isn’t the right type or convertible, raise an error
msg = f"{name} needs to be of one of {join_english(ArrayDataStructureType.qualnames())}, not {type(value)}."
if e is not None:
msg += " (Failed to convert it to an array, see above for details.)"
> raise ValueError(msg) from e
E ValueError: Varm 'replaced' needs to be of one of np.ndarray, numpy.ma.core.MaskedArray, scipy.sparse.spmatrix, awkward.Array, h5py.Dataset, zarr.Array, zappy.base.ZappyArray, anndata.experimental.[CSC,CSR]Dataset, dask.array.Array, cupy.ndarray, or cupyx.scipy.sparse.spmatrix, not <class 'pandas.core.series.Series'>.
/opt/homebrew/Caskroom/mambaforge/base/envs/py12-pertpy-env/lib/python3.12/site-packages/anndata/_core/storage.py:104: ValueError
The text was updated successfully, but these errors were encountered:
Describe the bug
With the new anndata 0.10.9 release, anndata no longer allows pandas DataFrames to be stored in
varm
and throws an error when doing so (see 3rd bullet point of release notes here). When refitting a Deseq model (e.g., by runningdds.deseq2
wheredds = DeseqDataSet
withrefit_cooks=True
) and no sample can be replaced, apandas.Series
is stored inadata.varm
, resulting in aValueError
. I believe this issue can be fixed by storing the data differently, for example, as a binary (0/1) in a numpy array.This is the line of code causing the failure.
To Reproduce
Desktop (please complete the following information):
Error Traceback
The text was updated successfully, but these errors were encountered: