Skip to content

Commit dd6fd9a

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent f60e861 commit dd6fd9a

File tree

2 files changed

+23
-33
lines changed

2 files changed

+23
-33
lines changed

tests/pl/test_render_shapes.py

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -689,47 +689,35 @@ def test_plot_can_handle_nan_values_in_color_data(self, sdata_blobs: SpatialData
689689
"""Test that NaN values in color data are handled gracefully."""
690690
sdata_blobs["table"].obs["region"] = pd.Categorical(["blobs_circles"] * sdata_blobs["table"].n_obs)
691691
sdata_blobs["table"].uns["spatialdata_attrs"]["region"] = "blobs_circles"
692-
692+
693693
# Add color column with NaN values
694694
sdata_blobs.shapes["blobs_circles"]["color_with_nan"] = [1.0, 2.0, np.nan, 4.0, 5.0]
695-
695+
696696
# Test that rendering works with NaN values and issues warning
697697
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()
698+
sdata_blobs.pl.render_shapes(element="blobs_circles", color="color_with_nan", na_color="red").pl.show()
703699

704700
def test_plot_colorbar_normalization_with_nan_values(self, sdata_blobs: SpatialData):
705701
"""Test that colorbar normalization works correctly with NaN values."""
706702
sdata_blobs["table"].obs["region"] = pd.Categorical(["blobs_polygons"] * sdata_blobs["table"].n_obs)
707703
sdata_blobs["table"].uns["spatialdata_attrs"]["region"] = "blobs_polygons"
708-
704+
709705
sdata_blobs.shapes["blobs_polygons"]["color_with_nan"] = [1.0, 2.0, np.nan, 4.0, 5.0]
710-
706+
711707
# 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()
708+
sdata_blobs.pl.render_shapes(element="blobs_polygons", color="color_with_nan", na_color="gray").pl.show()
717709

718710
def test_plot_can_handle_non_numeric_radius_values(self, sdata_blobs: SpatialData):
719711
"""Test that non-numeric radius values are handled gracefully."""
720712
sdata_blobs.shapes["blobs_circles"]["radius_mixed"] = [1.0, "invalid", 3.0, np.nan, 5.0]
721-
713+
722714
sdata_blobs.pl.render_shapes(element="blobs_circles", color="red").pl.show()
723715

724716
def test_plot_can_handle_mixed_numeric_and_color_data(self, sdata_blobs: SpatialData):
725717
"""Test handling of mixed numeric and color-like data."""
726718
sdata_blobs["table"].obs["region"] = pd.Categorical(["blobs_circles"] * sdata_blobs["table"].n_obs)
727719
sdata_blobs["table"].uns["spatialdata_attrs"]["region"] = "blobs_circles"
728-
720+
729721
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()
722+
723+
sdata_blobs.pl.render_shapes(element="blobs_circles", color="mixed_data", na_color="gray").pl.show()

tests/pl/test_utils.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,15 @@ def test_is_color_like(color_result: tuple[ColorLike, bool]):
9292
def test_extract_scalar_value():
9393
"""Test the new _extract_scalar_value function for robust numeric conversion."""
9494
from spatialdata_plot.pl.utils import _extract_scalar_value
95-
95+
9696
# Test basic functionality
9797
assert _extract_scalar_value(3.14) == 3.14
9898
assert _extract_scalar_value(42) == 42.0
99-
99+
100100
# Test with collections
101101
assert _extract_scalar_value(pd.Series([1.0, 2.0, 3.0])) == 1.0
102102
assert _extract_scalar_value([1.0, 2.0, 3.0]) == 1.0
103-
103+
104104
# Test edge cases
105105
assert _extract_scalar_value(np.nan) == 0.0
106106
assert _extract_scalar_value("invalid") == 0.0
@@ -109,15 +109,17 @@ def test_extract_scalar_value():
109109

110110
def test_plot_can_handle_per_row_rgba_colors(sdata_blobs: SpatialData):
111111
"""Test handling of per-row RGBA color arrays."""
112-
rgba_colors = np.array([
113-
[1.0, 0.0, 0.0, 1.0], # red
114-
[0.0, 1.0, 0.0, 1.0], # green
115-
[0.0, 0.0, 1.0, 1.0], # blue
116-
[1.0, 1.0, 0.0, 1.0], # yellow
117-
[1.0, 0.0, 1.0, 1.0], # magenta
118-
])
112+
rgba_colors = np.array(
113+
[
114+
[1.0, 0.0, 0.0, 1.0], # red
115+
[0.0, 1.0, 0.0, 1.0], # green
116+
[0.0, 0.0, 1.0, 1.0], # blue
117+
[1.0, 1.0, 0.0, 1.0], # yellow
118+
[1.0, 0.0, 1.0, 1.0], # magenta
119+
]
120+
)
119121
sdata_blobs.shapes["blobs_circles"]["rgba_colors"] = rgba_colors.tolist()
120-
122+
121123
sdata_blobs.pl.render_shapes(element="blobs_circles", color="rgba_colors").pl.show()
122124

123125

0 commit comments

Comments
 (0)