Skip to content

Commit 4161d7d

Browse files
ieivanovclaude
andcommitted
feat: enforce name matches plate_row/plate_col
When plate_row and plate_col are set, the position name is always derived from them (e.g., plate_row=0, plate_col=0 -> "A1"). Providing an explicit name that doesn't match raises ValueError. This ensures the position name and zarr well path are always coupled. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent c44ebc9 commit 4161d7d

1 file changed

Lines changed: 14 additions & 10 deletions

File tree

src/useq/_position.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,9 @@ class PositionBase(MutableModel):
4040
z : float | None
4141
Z position in microns.
4242
name : str | None
43-
Optional name for the position. If not provided but `plate_row` and
44-
`plate_col` are set, a well name is auto-generated (e.g., "A1").
43+
Optional name for the position. When `plate_row` and `plate_col` are
44+
set, the name is always derived from them (e.g., "A1"). Providing a
45+
name that doesn't match the plate coordinates raises a ValueError.
4546
sequence : MDASequence | None
4647
Optional MDASequence relative this position.
4748
plate_row : int | None
@@ -105,14 +106,17 @@ def __round__(self, ndigits: "SupportsIndex | None" = None) -> "Self":
105106

106107
@model_validator(mode="after")
107108
def _name_from_plate(self) -> "Self":
108-
"""Auto-generate name from plate_row/plate_col if not provided."""
109-
if (
110-
self.name is None
111-
and self.plate_row is not None
112-
and self.plate_col is not None
113-
):
114-
name = f"{_index_to_row_name(self.plate_row)}{self.plate_col + 1}"
115-
object.__setattr__(self, "name", name)
109+
"""Set name from plate_row/plate_col. Errors if an explicit name conflicts."""
110+
if self.plate_row is not None and self.plate_col is not None:
111+
well_name = f"{_index_to_row_name(self.plate_row)}{self.plate_col + 1}"
112+
if self.name is not None and self.name != well_name:
113+
raise ValueError(
114+
f"Position name {self.name!r} does not match plate_row="
115+
f"{self.plate_row}, plate_col={self.plate_col} (expected "
116+
f"{well_name!r}). Remove the name to auto-generate it from "
117+
f"plate coordinates."
118+
)
119+
object.__setattr__(self, "name", well_name)
116120
return self
117121

118122
@model_validator(mode="before")

0 commit comments

Comments
 (0)