Skip to content

Categorical color obs column crashes the plotting #355

Description

@sinanugur

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'

Activity

  1. self-assigned this
    on Sep 12, 2024
  2. removed their assignment
    on Sep 30, 2024
  3. LucaMarconato commented on Oct 3, 2024

    @LucaMarconato
    Member

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

    • plotting categoricals when no values are np.nan works
    • plotting categoricals when there are np.nan values gives an error. I have tried both when the column is in a table.obs and when the column is directly in the GeoDataFrame.
      • When the nan value is in table.obs I get your error
      • When the nan value is in a column of the GeoDataFrame, the plot fails with a different error.
    • I have tried also putting a nan value in a continuous column. I report the following:
      • When the nan value is in table.obs, no exception is raised but the plot looks all gray (while it should not). So it still fails.
      • When the nan value is in a column of the GeoDataFrame, the plot fails (with the same error for the categorical case for dataframe columns).

    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 nan values in table.obs columns (both categorical and continous).
      • add nan values in table.X
    • tests for points, shapes:
      • add nan values in the dataframe column (both categorical and continous)
  4. timtreis commented on Oct 3, 2024

    @timtreis
    Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions