Skip to content

Boolean indexing error #182

Closed
Closed

Description

@jacobkimmel

Hi anndata folks,

After updating from anndata==0.6.18 => anndata==0.6.22.post1 I encounter the following error whenever I try to subset an AnnData object using boolean indices

adata = anndata.AnnData(...)
print(adata.shape[0])
# returns: N

bidx = adata.obs[some_variable] == some_value
subset = adata[bidx, :].copy()
print(subset.shape[0])
# returns: M

second_bidx = subset.obs[some_variable1] == some_value1
subset[second_bidx, :]

# boolean index did not match indexed array along dimension 0, dimension is N, boolean index in M

This appears to be an issue with subsetting the .raw attribute, because everything works fine if I set

adata.raw = None

before the subsetting operations above.

Activity

  1. ivirshup commented on Jul 12, 2019

    @ivirshup
    Member

    Thanks for the bug report!

    On the current release, on my machine, this doesn't throw the error:

    pbmc = sc.datasets.pbmc68k_reduced()
    bidx1 = pbmc.obs["bulk_labels"] == "Dendritic"
    subset = pbmc[bidx1, :].copy()
    
    bidx2 = subset.obs["phase"] == "G1" 
    subset[bidx2]

    This does:

    pbmc = sc.datasets.pbmc68k_reduced()
    bidx1 = pbmc.obs["bulk_labels"] == "Dendritic"
    subset = pbmc[bidx1, :].copy()
    
    bidx2 = subset.obs["phase"] == "G1" 
    subset[bidx2, :]

    This error occurs at least as far back as 0.6.20, but does not occur under #164.

  2. gokceneraslan commented on Jul 26, 2019

    @gokceneraslan
    Contributor

    I hit this bug too. Here is a simpler code to reproduce this:

    import scanpy as sc
    
    adata = sc.datasets.paul15()
    adata.raw = adata
    
    ad = adata[:300]
    ad = ad[ad.obs.paul15_clusters == '7MEP', :]
    ad

    The error goes away if you do not index the gene dimension:

    import scanpy as sc
    
    adata = sc.datasets.paul15()
    adata.raw = adata
    
    ad = adata[:300]
    ad = ad[ad.obs.paul15_clusters == '7MEP'] # note that there is no :
    ad
  3. ivirshup commented on Jul 31, 2019

    @ivirshup
    Member

    Thanks @gokceneraslan!

    Now that #164 is merged, this is fixed on master.

  4. jacobkimmel commented on Jul 31, 2019

    @jacobkimmel
    Author

    Awesome, thanks @ivirshup!

    Feel free to close.

  5. added theissue type on Nov 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions