scverse / spatialdata-plot

Static plotting for spatialdata
BSD 3-Clause "New" or "Revised" License
25 stars 13 forks source link

pl.render_shapes fail when missing values among category #278

Open sinanugur opened 2 weeks ago

sinanugur commented 2 weeks ago

Hi,

I want to visualize an object with missing values. However, it seems that missing values crash pl.render_shapes method. It returns a TypeError.

Here is the output. Thanks for your help.

´´´ TypeError Traceback (most recent call last) Cell In[350], line 1 ----> 1 sdata_small.pl.render_images("crc_full_image").pl.render_shapes( 2 f"crc_square_00{resolution}um", color="macro_cluster", cmap="tab20",fill_alpha=0.5 3 ).pl.show(coordinate_systems="global", title=f"Macrophage clusters", legend_fontsize=8)

File ~/miniconda/envs/spatialio/lib/python3.10/site-packages/spatialdata_plot/pl/basic.py:864, in PlotAccessor.show(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) 862 if wanted_shapes_on_this_cs: 863 params_copy = _update_params(sdata, params_copy, wanted_shapes_on_this_cs, "shapes") --> 864 _render_shapes( 865 sdata=sdata, 866 render_params=params_copy, 867 coordinate_system=cs, 868 ax=ax, 869 fig_params=fig_params, 870 scalebar_params=scalebar_params, 871 legend_params=legend_params, 872 ) 874 elif cmd == "render_points" and has_points: 875 wanted_elements, wanted_points_on_this_cs, wants_points = _get_wanted_render_elements( 876 sdata, wanted_elements, params_copy, cs, "points" 877 )

File ~/miniconda/envs/spatialio/lib/python3.10/site-packages/spatialdata_plot/pl/render.py:108, in _render_shapes(sdata, render_params, coordinate_system, ax, fig_params, scalebar_params, legend_params) ... 1616 f"category ({fill_value}), set the categories first" 1617 ) from None 1618 return fill_value

TypeError: Cannot setitem on a Categorical with a new category (#d3d3d3ff), set the categories first ´´´

sinanugur commented 2 weeks ago

OK, this issue has been resolved in the devel version. Thanks.

giovp commented 2 weeks ago

thanks @sinanugur , I'll move the issue to spatialdata-plot, please if the issue is solved feel free to close it thank you!