Skip to content

Commit cb2bdfb

Browse files
committed
Slim obs/var shadow regression test
1 parent 175d013 commit cb2bdfb

1 file changed

Lines changed: 4 additions & 38 deletions

File tree

tests/pl/test_utils.py

Lines changed: 4 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -423,21 +423,11 @@ def test_color_column_collision_on_annotating_table_raises():
423423

424424

425425
def test_color_key_obs_var_shadow_raises():
426-
# regression test for #621: when the same key exists in both `table.obs.columns`
427-
# and `table.var_names`, upstream `_get_table_origins` silently returns only the
428-
# obs origin (elif chain). Surface the ambiguity at the plotting layer instead.
429-
pts = PointsModel.parse(pd.DataFrame({"x": [1.0, 2.0, 3.0, 4.0], "y": [1.0, 2.0, 3.0, 4.0]}))
430-
obs = pd.DataFrame(
431-
{
432-
"instance_id": [0, 1, 2, 3],
433-
"region": ["pts"] * 4,
434-
"GeneA": [0.9, 0.8, 0.7, 0.6],
435-
}
436-
)
437-
obs.index = obs.index.astype(str)
438-
X = np.array([[1.0, 0.5], [0.8, 0.2], [0.3, 0.9], [0.1, 0.7]])
426+
# regression test for #621
427+
pts = PointsModel.parse(pd.DataFrame({"x": [1.0, 2.0], "y": [1.0, 2.0]}))
428+
obs = pd.DataFrame({"instance_id": [0, 1], "region": ["pts"] * 2, "GeneA": [0.9, 0.6]}, index=["0", "1"])
439429
table = TableModel.parse(
440-
AnnData(X=X, obs=obs, var=pd.DataFrame(index=["GeneA", "GeneB"])),
430+
AnnData(X=np.zeros((2, 1)), obs=obs, var=pd.DataFrame(index=["GeneA"])),
441431
region=["pts"],
442432
region_key="region",
443433
instance_key="instance_id",
@@ -447,30 +437,6 @@ def test_color_key_obs_var_shadow_raises():
447437
with pytest.raises(ValueError, match=r"'GeneA'.*ambiguous.*obs\.columns.*var_names"):
448438
sdata.pl.render_points("pts", color="GeneA", table_name="t").pl.show()
449439

450-
# Negative control: only in var → no error.
451-
obs_var_only = pd.DataFrame(
452-
{"instance_id": [0, 1, 2, 3], "region": ["pts"] * 4},
453-
index=[str(i) for i in range(4)],
454-
)
455-
table_var_only = TableModel.parse(
456-
AnnData(X=X, obs=obs_var_only, var=pd.DataFrame(index=["GeneA", "GeneB"])),
457-
region=["pts"],
458-
region_key="region",
459-
instance_key="instance_id",
460-
)
461-
sdata_var_only = SpatialData(points={"pts": pts}, tables={"t": table_var_only})
462-
sdata_var_only.pl.render_points("pts", color="GeneA", table_name="t").pl.show()
463-
464-
# Negative control: only in obs → no error.
465-
table_obs_only = TableModel.parse(
466-
AnnData(X=X, obs=obs, var=pd.DataFrame(index=["G1", "G2"])),
467-
region=["pts"],
468-
region_key="region",
469-
instance_key="instance_id",
470-
)
471-
sdata_obs_only = SpatialData(points={"pts": pts}, tables={"t": table_obs_only})
472-
sdata_obs_only.pl.render_points("pts", color="GeneA", table_name="t").pl.show()
473-
474440

475441
def test_explicit_table_name_honored_when_element_has_same_column():
476442
# regression test for #620: explicit table_name= must not be silently

0 commit comments

Comments
 (0)