From 75296bb210d141fa1de24960412bfcab77a9604d Mon Sep 17 00:00:00 2001 From: Isaac Virshup Date: Sun, 7 Jul 2019 16:35:11 +1000 Subject: [PATCH] Fix access to raw.X by .raw.{obs,var}_vector Previously had relied on subsetting the entire object to get vector of X. Now just normalizes index. Also stops throwing warning about changing behaviour. Whoops. https://github.com/theislab/anndata/issues/171#issuecomment-508619952 --- anndata/core/anndata.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/anndata/core/anndata.py b/anndata/core/anndata.py index 6cf5f7f8d..f3a9fe8fe 100644 --- a/anndata/core/anndata.py +++ b/anndata/core/anndata.py @@ -385,7 +385,8 @@ def var_vector(self, k: str) -> np.ndarray: if k in self.var: return self.var[k].values else: - a = self[k, :].X + idx = self._normalize_indices((k, slice(None))) + a = self.X[idx] if issparse(a): a = a.toarray() return np.ravel(a) @@ -409,7 +410,8 @@ def obs_vector(self, k: str) -> np.ndarray: A one dimensional nd array, with values for each obs in the same order as `.obs_names`. """ - a = self[:, k].X + idx = self._normalize_indices((slice(None), k)) + a = self.X[idx] if issparse(a): a = a.toarray() return np.ravel(a)