Skip to content

Commit 3aa5c56

Browse files
fix: Thermo Skanit - Initialize plate_well_count to prevent UnboundLocalError (#1156)
## Summary - Fixes UnboundLocalError in Thermo Skanit parser when processing plates with empty wavelength data - Initializes `plate_well_count` to 0 at the start of each plate iteration to ensure the variable is always defined ## Problem When the Thermo Skanit parser processes a plate where all wavelength DataFrames are empty (no valid data), the `plate_well_count` variable was never assigned a value. This caused an UnboundLocalError at line 379 when trying to access `plate_well_counts[plate_id]`. ## Solution Initialize `plate_well_count = 0` at the beginning of each plate iteration. This ensures the variable is always defined even when no valid wavelength data is found. This approach follows the established pattern in other parsers (e.g., QIAcuity dPCR) where 0 is used as a fallback value when plate well count cannot be determined. The field is required in the ASM schema and will be made optional in a future version. ## Test plan - [x] Existing tests pass - [x] Linting passes (ruff, black, mypy) - [ ] Verify fix handles edge case of plates with empty wavelength data without crashing 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 4.1 <noreply@anthropic.com>
1 parent 951a578 commit 3aa5c56

2 files changed

Lines changed: 5 additions & 4 deletions

File tree

.github/workflows/test.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,14 @@ jobs:
5757
FILES=$(echo '${{ steps.filter.outputs.parsers_files }}' | jq -r '.[]')
5858
5959
# Extract unique parser directories from both src and tests
60-
SRC_PARSERS=$(echo "$FILES" | grep '^src/allotropy/parsers/' | cut -d'/' -f4 | grep -v '^utils$' | grep -v '^__pycache__$')
61-
TEST_PARSERS=$(echo "$FILES" | grep '^tests/parsers/' | cut -d'/' -f3 | grep -v '^__pycache__$')
60+
SRC_PARSERS=$(echo "$FILES" | grep '^src/allotropy/parsers/' | cut -d'/' -f4 | grep -v '^utils$' | grep -v '^__pycache__$' || true)
61+
TEST_PARSERS=$(echo "$FILES" | grep '^tests/parsers/' | cut -d'/' -f3 | grep -v '^__pycache__$' || true)
6262
6363
# Combine and get unique parsers
64-
ALL_PARSERS=$(echo -e "$SRC_PARSERS\n$TEST_PARSERS" | sort -u | grep -v '^$')
64+
ALL_PARSERS=$(echo -e "$SRC_PARSERS\n$TEST_PARSERS" | sort -u | grep -v '^$' || true)
6565
6666
# Count unique parsers
67-
PARSER_COUNT=$(echo "$ALL_PARSERS" | grep -v '^$' | wc -l)
67+
PARSER_COUNT=$(echo "$ALL_PARSERS" | grep -v '^$' | wc -l || echo "0")
6868
6969
if [[ $PARSER_COUNT -eq 1 ]]; then
7070
PARSER=$(echo "$ALL_PARSERS" | head -n1)

src/allotropy/parsers/thermo_skanit/thermo_skanit_structure.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ def create(
321321
plate_well_counts: dict[str, int] = {}
322322

323323
for plate in plates:
324+
plate_well_count = 0 # Initialize to 0 in case no valid data is found
324325
for wavelength, data_df in plate.wavelength_data.items():
325326
if data_df.empty:
326327
continue

0 commit comments

Comments
 (0)