Skip to content

Commit 96582ac

Browse files
authored
Fix render_points crash when coloring by spatial coord (x/y) (#671)
1 parent 59da170 commit 96582ac

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

src/spatialdata_plot/pl/render.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -772,7 +772,8 @@ def _render_points(
772772
):
773773
points = points[coords].compute()
774774
else:
775-
coords += [col_for_color]
775+
if col_for_color not in coords:
776+
coords.append(col_for_color)
776777
points = points[coords].compute()
777778

778779
added_color_from_table = False

tests/pl/test_render_points.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,6 +1040,18 @@ def test_render_points_color_by_z_with_extra_columns():
10401040
plt.close(fig)
10411041

10421042

1043+
@pytest.mark.parametrize("color", ["x", "y"])
1044+
def test_render_points_color_by_coord_axis(color):
1045+
# regression test for #613
1046+
pts = PointsModel.parse(pd.DataFrame({"x": [1.0, 2.0, 3.0], "y": [1.0, 2.0, 3.0]}))
1047+
sdata = SpatialData(points={"p": pts})
1048+
fig, ax = plt.subplots()
1049+
try:
1050+
sdata.pl.render_points("p", color=color).pl.show(ax=ax)
1051+
finally:
1052+
plt.close(fig)
1053+
1054+
10431055
def test_render_points_disjoint_instance_ids_clear_error():
10441056
# regression test for #603: disjoint instance_id values must raise a clear ValueError
10451057
points = PointsModel.parse(pd.DataFrame({"x": [1.0, 2.0, 3.0], "y": [1.0, 2.0, 3.0]}))

0 commit comments

Comments
 (0)