Skip to content

Commit c70db64

Browse files
committed
Use dense Gaussian-cluster points for density visual tests
The shared blobs fixture only has ~200 points scattered across a 500x500 canvas, so density renders as nearly invisible single-pixel dots. Add a dedicated sdata_dense_points fixture (~60k points across three Gaussian clusters, with a categorical "gene" column) so the test_plot_density_* cases produce a meaningful visual baseline. Also fixes test_plot_density_categorical_with_groups, which previously passed palette="tab20" alongside a single-element groups list -- our palette parser treats single-string + single-group as a literal color and rejected "tab20" with "Unknown color".
1 parent ad522c7 commit c70db64

2 files changed

Lines changed: 39 additions & 11 deletions

File tree

tests/conftest.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,34 @@ def sdata_blobs() -> SpatialData:
8080
return blobs()
8181

8282

83+
@pytest.fixture()
84+
def sdata_dense_points() -> SpatialData:
85+
"""Dense (~20k) multi-cluster points dataset for density-rendering visual tests.
86+
87+
The blobs fixture is too sparse (~200 points across 500x500) for density to render
88+
meaningfully without spreading; this fixture provides a Gaussian-cluster cloud with
89+
a categorical ``gene`` column so the per-category density branch is exercised too.
90+
"""
91+
rng = get_standard_RNG()
92+
n_per_cluster = 20000
93+
centers = [(120, 120), (380, 150), (250, 380)]
94+
genes = ["gene_a", "gene_b", "gene_c"]
95+
xs, ys, gs = [], [], []
96+
for (cx, cy), gene in zip(centers, genes, strict=True):
97+
xs.append(rng.normal(loc=cx, scale=18, size=n_per_cluster))
98+
ys.append(rng.normal(loc=cy, scale=18, size=n_per_cluster))
99+
gs.extend([gene] * n_per_cluster)
100+
df = pd.DataFrame(
101+
{
102+
"x": np.concatenate(xs).clip(0, 500),
103+
"y": np.concatenate(ys).clip(0, 500),
104+
"gene": pd.Categorical(gs, categories=genes),
105+
}
106+
)
107+
points = PointsModel.parse(df)
108+
return SpatialData(points={"dense_points": points})
109+
110+
83111
@pytest.fixture()
84112
def sdata_blobs_str() -> SpatialData:
85113
return blobs(n_channels=5, c_coords=["c1", "c2", "c3", "c4", "c5"])

tests/pl/test_render_points.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -172,22 +172,22 @@ def test_plot_datashader_continuous_color(self, sdata_blobs: SpatialData):
172172
method="datashader",
173173
).pl.show()
174174

175-
def test_plot_density_plain(self, sdata_blobs: SpatialData):
176-
sdata_blobs.pl.render_points("blobs_points", density=True).pl.show()
175+
def test_plot_density_plain(self, sdata_dense_points: SpatialData):
176+
sdata_dense_points.pl.render_points("dense_points", density=True).pl.show()
177177

178-
def test_plot_density_categorical(self, sdata_blobs: SpatialData):
179-
sdata_blobs.pl.render_points("blobs_points", color="genes", palette="tab20", density=True).pl.show()
178+
def test_plot_density_categorical(self, sdata_dense_points: SpatialData):
179+
sdata_dense_points.pl.render_points("dense_points", color="gene", density=True).pl.show()
180180

181-
def test_plot_density_categorical_with_groups(self, sdata_blobs: SpatialData):
182-
sdata_blobs.pl.render_points(
183-
"blobs_points", color="genes", groups=["gene_a"], palette="tab20", density=True
181+
def test_plot_density_categorical_with_groups(self, sdata_dense_points: SpatialData):
182+
sdata_dense_points.pl.render_points(
183+
"dense_points", color="gene", groups=["gene_a", "gene_b"], density=True
184184
).pl.show()
185185

186-
def test_plot_density_how_log(self, sdata_blobs: SpatialData):
187-
sdata_blobs.pl.render_points("blobs_points", density=True, density_how="log").pl.show()
186+
def test_plot_density_how_log(self, sdata_dense_points: SpatialData):
187+
sdata_dense_points.pl.render_points("dense_points", density=True, density_how="log").pl.show()
188188

189-
def test_plot_density_how_eq_hist(self, sdata_blobs: SpatialData):
190-
sdata_blobs.pl.render_points("blobs_points", density=True, density_how="eq_hist").pl.show()
189+
def test_plot_density_how_eq_hist(self, sdata_dense_points: SpatialData):
190+
sdata_dense_points.pl.render_points("dense_points", density=True, density_how="eq_hist").pl.show()
191191

192192
def test_plot_points_categorical_color_column_matplotlib(self, sdata_blobs: SpatialData):
193193
sdata_blobs.pl.render_points("blobs_points", color="genes", method="matplotlib").pl.show()

0 commit comments

Comments
 (0)