spatialdata-plot
spatialdata-plot copied to clipboard
Categorical color obs column crashes the plotting
Hi,
When the "color" is categorical, it crashes and returns ValueError in version 0.2.6. The categorial "test" column contains NaN values. There are 11 possible categories.
This code was working perfectly in version 0.2.4.
Cheers,
sdata_small.pl.render_images("queried_cytassist",alpha=1).pl.render_shapes(
f"{sample_id}_square_00{bin_size}um", color="test",method="matplotlib"
).pl.show(coordinate_systems="global", title="Test clusters", legend_fontsize=8,figsize=(10,10),dpi=200,save=None)
[359](https://file+.vscode-resource.vscode-cdn.net/Users/sium/projects/visiumhd/testing/notebooks/~/miniconda/envs/testing/lib/python3.11/site-packages/spatialdata_plot/pl/utils.py:359) "Could not convert values in the `color` column to float, if `color` column represents"
[360](https://file+.vscode-resource.vscode-cdn.net/Users/sium/projects/visiumhd/testing/notebooks/~/miniconda/envs/testing/lib/python3.11/site-packages/spatialdata_plot/pl/utils.py:360) " categories, set the column to categorical dtype."
[361](https://file+.vscode-resource.vscode-cdn.net/Users/sium/projects/visiumhd/testing/notebooks/~/miniconda/envs/testing/lib/python3.11/site-packages/spatialdata_plot/pl/utils.py:361) ) from e
TypeError: '<' not supported between instances of 'str' and 'float'
I tried to reproduce with Visium HD data and I report the following:
- plotting categoricals when no values are
np.nanworks - plotting categoricals when there are
np.nanvalues gives an error. I have tried both when the column is in atable.obsand when the column is directly in theGeoDataFrame.- When the
nanvalue is intable.obsI get your error - When the
nanvalue is in a column of theGeoDataFrame, the plot fails with a different error.
- When the
- I have tried also putting a
nanvalue in a continuous column. I report the following:- When the
nanvalue is intable.obs, no exception is raised but the plot looks all gray (while it should not). So it still fails. - When the
nanvalue is in a column of theGeoDataFrame, the plot fails (with the same error for the categorical case for dataframe columns).
- When the
Actionable for @sinanugur. I suggest to remove the rows with nan values for the moment.
Actionable for us. I suggest to support the handing of nan values and add the following tests:
- [ ] tests for labels, points, shapes:
- [ ] add
nanvalues intable.obscolumns (both categorical and continous). - [ ] add
nanvalues intable.X
- [ ] add
- [ ] tests for points, shapes:
- [ ] add
nanvalues in the dataframe column (both categorical and continous)
- [ ] add
Thank you so much for the triage @LucaMarconato! ❤️