Skip to content

Commit

Permalink
adapted to anndata not exporting anndata.base anymore
Browse files Browse the repository at this point in the history
Adapting according to discussion at scverse/anndata#174.
  • Loading branch information
davidsebfischer committed Jul 30, 2019
1 parent 46ea81f commit b3a1b37
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions batchglm/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
except ImportError:
anndata = None

try:
from anndata.base import Raw
except ImportError:
from anndata import Raw


def _sparse_to_xarray(data, dims):
num_observations, num_features = data.shape
Expand Down Expand Up @@ -54,7 +59,7 @@ def fetch_X(idx):


def xarray_from_data(
data: Union[anndata.AnnData, anndata.base.Raw, xr.DataArray, xr.Dataset, np.ndarray, scipy.sparse.csr_matrix],
data: Union[anndata.AnnData, Raw, xr.DataArray, xr.Dataset, np.ndarray, scipy.sparse.csr_matrix],
dims: Union[Tuple, List] = ("observations", "features")
):
"""
Expand All @@ -65,7 +70,7 @@ def xarray_from_data(
:param dims: tuple or list with two strings. Specifies the names of the xarray dimensions.
:return: xr.DataArray of shape `dims`
"""
if anndata is not None and (isinstance(data, anndata.AnnData) or isinstance(data, anndata.base.Raw)):
if anndata is not None and (isinstance(data, anndata.AnnData) or isinstance(data, Raw)):
# Anndata.raw does not have obs_names.
if isinstance(data, anndata.AnnData):
obs_names = np.asarray(data.obs_names)
Expand Down

0 comments on commit b3a1b37

Please sign in to comment.