Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
- `location` parameter of `assign_child_resource` is not optional (https://github.com/PyLabRobot/pylabrobot/pull/336)
- `Resource.get_absolute_location` raises `NoLocationError` instead of `AssertionError` when absolute location is not defined (https://github.com/PyLabRobot/pylabrobot/pull/338)
- `no_trash` and `no_teaching_rack` were renamed to `with_trash` and `with_teaching_rack` to avoid double negatives (https://github.com/PyLabRobot/pylabrobot/pull/347)
- `ItemizedResource.row` accepts a string ("A"-"P") in addition to an integer index.

### Added

Expand Down
19 changes: 17 additions & 2 deletions pylabrobot/resources/itemized_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,21 @@ def column(self, column: int) -> List[T]:
"""Get all items in the given column."""
return self[column * self.num_items_y : (column + 1) * self.num_items_y]

def row(self, row: int) -> List[T]:
"""Get all items in the given row."""
def row(self, row: Union[int, str]) -> List[T]:
"""Get all items in the given row.

Args:
row: The row index. Either an integer starting at ``0`` or a letter
``"A"``-``"P"`` (case insensitive) corresponding to ``0``-``15``.

Raises:
ValueError: If ``row`` is a string outside ``"A"``-``"P"``.
"""

if isinstance(row, str):
letter = row.upper()
if letter not in LETTERS[:16]:
raise ValueError("Row must be between 'A' and 'P'.")
row = LETTERS.index(letter)

return self[row :: self.num_items_y]
16 changes: 16 additions & 0 deletions pylabrobot/resources/itemized_resource_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,22 @@ def test_get_row(self):
],
)

def test_get_row_str(self):
self.assertEqual(
[w.name for w in self.plate.row("A")],
[w.name for w in self.plate.row(0)],
)
self.assertEqual(
[w.name for w in self.plate.row("d")],
[w.name for w in self.plate.row(3)],
)

def test_get_row_str_invalid(self):
with self.assertRaises(ValueError):
self.plate.row("Q")
with self.assertRaises(ValueError):
self.plate.row("AA")

def test_get_column(self):
self.assertEqual(
[w.name for w in self.plate.column(0)],
Expand Down