@@ -684,3 +684,52 @@ def test_warns_when_table_does_not_annotate_element(sdata_blobs: SpatialData):
684684 table_name = "other_table" ,
685685 ).pl .show ()
686686 )
687+
688+ def test_plot_can_handle_nan_values_in_color_data (self , sdata_blobs : SpatialData ):
689+ """Test that NaN values in color data are handled gracefully."""
690+ sdata_blobs ["table" ].obs ["region" ] = pd .Categorical (["blobs_circles" ] * sdata_blobs ["table" ].n_obs )
691+ sdata_blobs ["table" ].uns ["spatialdata_attrs" ]["region" ] = "blobs_circles"
692+
693+ # Add color column with NaN values
694+ sdata_blobs .shapes ["blobs_circles" ]["color_with_nan" ] = [1.0 , 2.0 , np .nan , 4.0 , 5.0 ]
695+
696+ # Test that rendering works with NaN values and issues warning
697+ with pytest .warns (UserWarning , match = "Found 1 NaN values in color data" ):
698+ sdata_blobs .pl .render_shapes (
699+ element = "blobs_circles" ,
700+ color = "color_with_nan" ,
701+ na_color = "red"
702+ ).pl .show ()
703+
704+ def test_plot_colorbar_normalization_with_nan_values (self , sdata_blobs : SpatialData ):
705+ """Test that colorbar normalization works correctly with NaN values."""
706+ sdata_blobs ["table" ].obs ["region" ] = pd .Categorical (["blobs_polygons" ] * sdata_blobs ["table" ].n_obs )
707+ sdata_blobs ["table" ].uns ["spatialdata_attrs" ]["region" ] = "blobs_polygons"
708+
709+ sdata_blobs .shapes ["blobs_polygons" ]["color_with_nan" ] = [1.0 , 2.0 , np .nan , 4.0 , 5.0 ]
710+
711+ # Test colorbar with NaN values - should use nanmin/nanmax
712+ sdata_blobs .pl .render_shapes (
713+ element = "blobs_polygons" ,
714+ color = "color_with_nan" ,
715+ na_color = "gray"
716+ ).pl .show ()
717+
718+ def test_plot_can_handle_non_numeric_radius_values (self , sdata_blobs : SpatialData ):
719+ """Test that non-numeric radius values are handled gracefully."""
720+ sdata_blobs .shapes ["blobs_circles" ]["radius_mixed" ] = [1.0 , "invalid" , 3.0 , np .nan , 5.0 ]
721+
722+ sdata_blobs .pl .render_shapes (element = "blobs_circles" , color = "red" ).pl .show ()
723+
724+ def test_plot_can_handle_mixed_numeric_and_color_data (self , sdata_blobs : SpatialData ):
725+ """Test handling of mixed numeric and color-like data."""
726+ sdata_blobs ["table" ].obs ["region" ] = pd .Categorical (["blobs_circles" ] * sdata_blobs ["table" ].n_obs )
727+ sdata_blobs ["table" ].uns ["spatialdata_attrs" ]["region" ] = "blobs_circles"
728+
729+ sdata_blobs .shapes ["blobs_circles" ]["mixed_data" ] = [1.0 , 2.0 , np .nan , "red" , 5.0 ]
730+
731+ sdata_blobs .pl .render_shapes (
732+ element = "blobs_circles" ,
733+ color = "mixed_data" ,
734+ na_color = "gray"
735+ ).pl .show ()
0 commit comments