Repository navigation
unable to plot shapes #175
Description
Hi,
I'm trying to plot the segmentation shapes of a MERSCOPE experiment using this code
sdata.pl.render_shapes().pl.show()
But I'm getting this error message
ValueError Traceback (most recent call last)
/tmp/ipykernel_7493/2213135397.py in ?()
----> 1 cropped_sdata.pl.render_shapes().pl.show()
/allen/programs/celltypes/workgroups/rnaseqanalysis/mFISH/michaelkunst/miniconda3/envs/SpatialData/lib/python3.10/site-packages/spatialdata_plot/pl/basic.py in ?(self, coordinate_systems, legend_fontsize, legend_fontweight, legend_loc, legend_fontoutline, na_in_legend, colorbar, wspace, hspace, ncols, frameon, figsize, dpi, fig, title, share_extent, pad_extent, ax, return_ax, save)
635 ]
636 )
637
638 elif cmd == "render_shapes" and has_shapes:
--> 639 _render_shapes(
640 sdata=sdata,
641 render_params=params,
642 coordinate_system=cs,
/allen/programs/celltypes/workgroups/rnaseqanalysis/mFISH/michaelkunst/miniconda3/envs/SpatialData/lib/python3.10/site-packages/spatialdata_plot/pl/render.py in ?(sdata, render_params, coordinate_system, ax, fig_params, scalebar_params, legend_params)
121 color_source_vector = color_source_vector[mask]
122 color_vector = color_vector[mask]
123 shapes = gpd.GeoDataFrame(shapes, geometry="geometry")
124
--> 125 _cax = _get_collection_shape(
126 shapes=shapes,
127 s=render_params.scale,
128 c=color_vector,
/allen/programs/celltypes/workgroups/rnaseqanalysis/mFISH/michaelkunst/miniconda3/envs/SpatialData/lib/python3.10/site-packages/spatialdata_plot/pl/utils.py in ?(shapes, c, s, norm, render_params, fill_alpha, outline_alpha, **kwargs)
220 # remove empty points/polygons
221 shapes_df = shapes_df[shapes_df["geometry"].apply(lambda geom: not geom.is_empty)]
222
223 # reset index of shapes_df for case of spatial query
--> 224 shapes_df = shapes_df.reset_index()
225
226 rows = []
227
/allen/programs/celltypes/workgroups/rnaseqanalysis/mFISH/michaelkunst/miniconda3/envs/SpatialData/lib/python3.10/site-packages/pandas/core/frame.py in ?(self, level, drop, inplace, col_level, col_fill, allow_duplicates, names)
6219 level_values = algorithms.take(
6220 level_values, lab, allow_fill=True, fill_value=lev._na_value
6221 )
6222
-> 6223 new_obj.insert(
6224 0,
6225 name,
6226 level_values,
/allen/programs/celltypes/workgroups/rnaseqanalysis/mFISH/michaelkunst/miniconda3/envs/SpatialData/lib/python3.10/site-packages/pandas/core/frame.py in ?(self, loc, column, value, allow_duplicates)
4930 "'self.flags.allows_duplicate_labels' is False."
4931 )
4932 if not allow_duplicates and column in self.columns:
4933 # Should this be a different kind of error??
-> 4934 raise ValueError(f"cannot insert {column}, already exists")
4935 if not is_integer(loc):
4936 raise TypeError("loc must be int")
4937 # convert non stdlib ints to satisfy typing checks
ValueError: cannot insert EntityID, already exists
Activity
LucaMarconato commentedon Oct 28, 2023
Hi @mkunst23, thanks for reporting. I have transferred the issue to the
spatialdata-plotrepository. I haven't seen the bug before. @timtreis @Sonja-Stockhaus any idea?Sonja-Stockhaus commentedon Oct 30, 2023
Hi! Thanks for the report @mkunst23. That definitely looks like a problem in
spatialdata-plot, I'll look into itSonja-Stockhaus commentedon Oct 30, 2023
@mkunst23 I couldn't reproduce the error, but I made a change that hopefully fixes the issue. Could you clone the branch https://github.com/scverse/spatialdata-plot/tree/bugfix/175-unable-to-plot-shapes and verify this, please?