scverse / spatialdata-plot

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

Categorical color obs column crashes the plotting #355

Open sinanugur opened 2 months ago

sinanugur commented 2 months ago

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'
LucaMarconato commented 1 month ago

I tried to reproduce with Visium HD data and I report the following:

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:

timtreis commented 1 month ago

Thank you so much for the triage @LucaMarconato! ❤️