Skip to content

Commit 046bd48

Browse files
fix: Beckman Coulter PharmSpec - add validation for Particle and approver label, add unittests (#1008)
Co-authored-by: Nathan Stender <nathan.stender@benchling.com>
1 parent d89a891 commit 046bd48

4 files changed

Lines changed: 44 additions & 2 deletions

File tree

src/allotropy/parsers/beckman_pharmspec/beckman_pharmspec_reader.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import pandas as pd
22

3+
from allotropy.exceptions import AllotropeConversionError
34
from allotropy.named_file_contents import NamedFileContents
45
from allotropy.parsers.utils.pandas import parse_header_row, read_excel, SeriesData
56

@@ -17,8 +18,19 @@ def __init__(self, named_file_contents: NamedFileContents) -> None:
1718
by finding the index first row which contains the word 'Particle' and ending right before
1819
the index of the first row containing 'Approver'.
1920
"""
20-
start = df[df[1].str.contains("Particle", na=False)].index.values[0]
21-
end = df[df[0].str.contains("Approver_", na=False)].index.values[0] - 1
21+
# Check for rows containing "Particle" in column 1
22+
particle_rows = df[df[1].str.contains("Particle", na=False)].index.values
23+
if len(particle_rows) == 0:
24+
msg = "Unable to find required 'Particle' marker in column 1 of the data file."
25+
raise AllotropeConversionError(msg)
26+
start = particle_rows[0]
27+
28+
# Check for rows containing "Approver_" in column 0
29+
approver_rows = df[df[0].str.contains("Approver_", na=False)].index.values
30+
if len(approver_rows) == 0:
31+
msg = "Unable to find required 'Approver_' marker in column 0 of the data file."
32+
raise AllotropeConversionError(msg)
33+
end = approver_rows[0] - 1
2234

2335
# The header data is everything up to the start of the data.
2436
# It is stored in two columns spread over the first 6 columns.
Binary file not shown.
Binary file not shown.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,36 @@
1+
from pathlib import Path
2+
3+
import pytest
4+
5+
from allotropy.exceptions import AllotropeConversionError
16
from allotropy.parser_factory import Vendor
7+
from allotropy.testing.utils import from_file
28
from tests.to_allotrope_test import ParserTest
39

10+
TESTDATA = Path(Path(__file__).parent, "testdata")
11+
412

513
class TestParser(ParserTest):
614
VENDOR = Vendor.BECKMAN_PHARMSPEC
15+
16+
17+
def test_to_allotrope_missing_particle_marker() -> None:
18+
with pytest.raises(
19+
AllotropeConversionError,
20+
match="Unable to find required 'Particle' marker in column 1 of the data file.",
21+
):
22+
from_file(
23+
f"{TESTDATA}/errors/hiac_missing_particle.xlsx",
24+
TestParser.VENDOR,
25+
)
26+
27+
28+
def test_to_allotrope_missing_approver_marker() -> None:
29+
with pytest.raises(
30+
AllotropeConversionError,
31+
match="Unable to find required 'Approver_' marker in column 0 of the data file.",
32+
):
33+
from_file(
34+
f"{TESTDATA}/errors/hiac_missing_approver.xlsx",
35+
TestParser.VENDOR,
36+
)

0 commit comments

Comments
 (0)