Skip to content

Commit 919fbbb

Browse files
fix: Accept numeric-only Machine ID in Mabtech APEX parser (#1231)
## Summary - Some APEX instruments export only a numeric serial number (e.g. `"554"`) in the Machine ID field instead of the expected `"Model Number"` format (e.g. `"IRIS 1234"`) - The strict regex caused an `AllotropeConversionError: Unable to interpret Machine ID` failure - Now handles bare numeric IDs by using the number as the serial and setting model to N/A ## Test plan - [x] Verified both failing files (`Copy_of_XX039002_2.xlsx`, `XX067088.xlsx`) now parse successfully - [x] Existing mabtech_apex tests still pass (4/4) 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 0058b39 commit 919fbbb

1 file changed

Lines changed: 15 additions & 11 deletions

File tree

src/allotropy/parsers/mabtech_apex/mabtech_apex_structure.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,29 +13,33 @@
1313
Metadata,
1414
ProcessedData,
1515
)
16-
from allotropy.exceptions import AllotropeParsingError
16+
from allotropy.exceptions import AllotropeConversionError, AllotropeParsingError
1717
from allotropy.parsers.constants import NOT_APPLICABLE
1818
from allotropy.parsers.mabtech_apex import constants
1919
from allotropy.parsers.utils.pandas import SeriesData
2020
from allotropy.parsers.utils.uuids import random_uuid_str
21-
from allotropy.parsers.utils.values import assert_not_none
2221

2322

2423
def create_metadata(plate_info: SeriesData, file_path: str) -> Metadata:
25-
machine_id = assert_not_none(
26-
re.match(
27-
"([A-Z]+[a-z]*) ([0-9]+)",
28-
plate_info[str, "Machine ID"],
29-
),
30-
msg="Unable to interpret Machine ID",
31-
)
24+
raw_machine_id = plate_info[str, "Machine ID"]
25+
machine_id_match = re.match(r"([A-Z]+[a-z]*) ([0-9]+)", raw_machine_id)
26+
27+
if machine_id_match:
28+
model_number = machine_id_match.group(1)
29+
serial_number = machine_id_match.group(2)
30+
elif re.fullmatch(r"[0-9]+", raw_machine_id):
31+
model_number = NOT_APPLICABLE
32+
serial_number = raw_machine_id
33+
else:
34+
msg = f"Unable to interpret Machine ID: {raw_machine_id}"
35+
raise AllotropeConversionError(msg)
3236

3337
return Metadata(
3438
device_identifier=NOT_APPLICABLE,
3539
software_name=constants.SOFTWARE_NAME,
3640
software_version=plate_info.get(str, "Software Version"),
37-
model_number=machine_id.group(1),
38-
equipment_serial_number=machine_id.group(2),
41+
model_number=model_number,
42+
equipment_serial_number=serial_number,
3943
file_name=Path(file_path).name,
4044
unc_path=plate_info.get(str, "Path", file_path),
4145
custom_info=plate_info.get_unread(),

0 commit comments

Comments
 (0)