Skip to content

Add more informative error message when pl.render_shapes color table columnhas a missmatch of length #316

Closed

Description

@pakiessling

I ran into the following:

sc.pp.filter_cells(sdata.tables["table"],min_counts=10)
sdata.pl.render_shapes("cellpose_boundaries",color="total_counts").pl.show()

File /work/rwth1209/enviroments/spatial_data/lib/python3.9/site-packages/spatialdata_plot/pl/utils.py:264, in _get_collection_shape.<locals>.assign_fill_and_outline_to_row(shapes, fill_c, outline_c, row, idx)
    262     row["outline_c"] = outline_c
    263 else:
--> 264     row["fill_c"] = fill_c[idx]
    265     row["outline_c"] = outline_c[idx]

IndexError: index 3424 is out of bounds for axis 0 with size 3424

sdata.shapes["cellpose_boundaries"]  = sdata.shapes["cellpose_boundaries"].loc[sdata.tables["table"].obs.index]
sdata.pl.render_shapes("cellpose_boundaries",color="total_counts").pl.show()
fixed!

I removed some cells from the table but their polygons remained. When plotting this led to a generic error.
Could be a "me" problem but I think it might be good idea to add a more explicit error message that tells the user what is going on. An alternative might be to plot the missmatched polygons with a NaN color

Activity

  1. changed the title [-]Add more informative error message when pl.render_shapes color table category has a missmatch of length[/-] [+]Add more informative error message when pl.render_shapes color table columnhas a missmatch of length[/+] on Aug 3, 2024
  2. timtreis commented on Aug 15, 2024

    @timtreis
    Member

    Hey @pakiessling, I'd actually say that in this case it's a "you" problem 😅 You're directly passing theAnnData object, so scanpy cannot really know it's dealing with a spatialdata object and spatialdata would have to do regular consistency checks or sth to notice that you modified the contained AnnData. I added a more explicit error message though.

  3. timtreis commented on Aug 15, 2024

    @timtreis
    Member

    @flying-sheep are there any plans for scanpy to natively work with SpatialData objects? Then this could happen automagically

  4. timtreis commented on Aug 15, 2024

    @timtreis
    Member

    @LucaMarconato do we have a similar way of filtering in spatialdata ?

  5. LucaMarconato commented on Aug 15, 2024

    @LucaMarconato
    Member

    Yes, we have the user-friendly match_element_to_table() and match_table_to_element() functions, which are subcases of the more powerful API join_spatialelement_table().

  6. LucaMarconato commented on Aug 15, 2024

    @LucaMarconato
    Member

    Anyway, I think that the bug reported may be related to this other bug: #169 and not fixable by the user itself. I'll write a MRE in the linked PR.

  7. LucaMarconato commented on Aug 15, 2024

    @LucaMarconato
    Member

    Same bug, continuing the discussion there. Workaround: manually filtering the shapes so that there are no shapes not in the table.

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