Skip to content

Failing to set value on view mutates anndata (makes it not a view) #142

Closed

Description

@ivirshup

Attributes which derive from the _SetItemMixin mutate the anndata object even when setting the values fails. Here's an example:

import scanpy as sc

pbmc = sc.datasets.pbmc68k_reduced()
subset = pbmc[pbmc.obs["bulk_labels"] == "Dendritic"]

subset.isview  # True
subset.obs["new_val"] = [1, 1]  # Raises ValueError
subset.isview  # False

I think the cause is line 391 from here: https://github.com/theislab/anndata/blob/34f4eb63710628fbc15e7050e5efcac1d7806062/anndata/base.py#L383-L392

The anndata is being modified before the value has been set. This could be averted by making a copy of the attribute to be modified, modifying that, then modifying the anndata object.

Activity

  1. added a commit that references this issue on May 8, 2019
  2. ivirshup commented on Sep 6, 2019

    @ivirshup
    MemberAuthor

    Fixed!

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

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions