Open LucaMarconato opened 11 months ago
I'm running into the same issue
Hi @timtreis I just noticed that this bug is still open. Do you have any timeline for a fix? Thanks 😊
Here is how to reproduce the problem. When the table has less rows than the shapes, the problem appears.
import matplotlib.pyplot as plt
from spatialdata.datasets import blobs_annotating_element
import spatialdata_plot
sdata = blobs_annotating_element("blobs_circles")
sdata['table'] = sdata['table'][:3]
sdata.pl.render_shapes("blobs_circles", color="instance_id").pl.show()
plt.show()
The behavior in napari
, that would be expected from the user also here, is that the plot should be possible independently of which rows are present in the table and the shapes (it could be that the table has some rows in common, some missing and some extra; and no guarantee is expected from the order of the rows).
In napari shapes that are not present in the table are plotted in gray, while rows that are present in the table but not in the shapes are simply ignored. The order is matched via the join_spatialelement_table()
API, which made the implementation easy.
The bug is related to this https://github.com/scverse/spatialdata-plot/issues/178 which if I remember well Sonja had fixed (and tests were added), I am looking for her PR. I think that plot can be made with any order so maybe the only uncovered cases are when there is a different number of rows between shapes and table. Using join_spatialelement_table()
would fi all of this.
Here are the PRs from Sonja https://github.com/scverse/spatialdata-plot/pull/163/files and https://github.com/scverse/spatialdata-plot/pull/177/files.
So it seems that:
join_spatialelement_table
is not used here, probably because it was not available at that time. Here is how it is used in napari-spatialdata
: https://github.com/scverse/napari-spatialdata/blob/b50df555d9c0e1335c99afc27bc7b63bf0324934/src/napari_spatialdata/_view.py#L404. If the data to plot is a subset, instead of join_spatialelement_table
, the approach is slightly different (it calls an internal function instead function that computes the join even when the table is not part of a SpatialData
object, as it happens for subset tables) https://github.com/scverse/napari-spatialdata/blob/b50df555d9c0e1335c99afc27bc7b63bf0324934/src/napari_spatialdata/_viewer.py#L672.Practically, to address the issue I suggest to proceed as follows:
napari-spatialdata
I have just noticed that the squidpy notebook can't make the last plot; it should be a quick fix. The latest version of the notebook (gonna be merge in main soon) is this one: https://github.com/scverse/spatialdata-notebooks/blob/fix/remove_napari/notebooks/examples/squidpy_integration.ipynb
The dataset used in the notebook is the xenium rep 1 data, it should be unchanged from the one we have downloaded and the S3 version should be up-to-date (I will re-enable the upload functions today/tomorrow, so for sure it will be up-to-date soon).
The problem seem to be due to the use of positional indices where ".loc" indices should have been used. Please see the screenshot: the
cell_id
andgdf.index
columns match, but it seems that at some point either a positional index for the table, either thetable.obs.index
has been used.Faulty line:
Traceback