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
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pandas as pd

from allotropy.exceptions import AllotropeConversionError
from allotropy.named_file_contents import NamedFileContents
from allotropy.parsers.utils.pandas import parse_header_row, read_excel, SeriesData

Expand All @@ -17,8 +18,19 @@ def __init__(self, named_file_contents: NamedFileContents) -> None:
by finding the index first row which contains the word 'Particle' and ending right before
the index of the first row containing 'Approver'.
"""
start = df[df[1].str.contains("Particle", na=False)].index.values[0]
end = df[df[0].str.contains("Approver_", na=False)].index.values[0] - 1
# Check for rows containing "Particle" in column 1
particle_rows = df[df[1].str.contains("Particle", na=False)].index.values
if len(particle_rows) == 0:
msg = "Unable to find required 'Particle' marker in column 1 of the data file."
raise AllotropeConversionError(msg)
start = particle_rows[0]

# Check for rows containing "Approver_" in column 0
approver_rows = df[df[0].str.contains("Approver_", na=False)].index.values
if len(approver_rows) == 0:
msg = "Unable to find required 'Approver_' marker in column 0 of the data file."
raise AllotropeConversionError(msg)
end = approver_rows[0] - 1

# The header data is everything up to the start of the data.
# It is stored in two columns spread over the first 6 columns.
Expand Down
Binary file not shown.
Binary file not shown.
30 changes: 30 additions & 0 deletions tests/parsers/beckman_pharmspec/to_allotrope_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,36 @@
from pathlib import Path

import pytest

from allotropy.exceptions import AllotropeConversionError
from allotropy.parser_factory import Vendor
from allotropy.testing.utils import from_file
from tests.to_allotrope_test import ParserTest

TESTDATA = Path(Path(__file__).parent, "testdata")


class TestParser(ParserTest):
VENDOR = Vendor.BECKMAN_PHARMSPEC


def test_to_allotrope_missing_particle_marker() -> None:
with pytest.raises(
AllotropeConversionError,
match="Unable to find required 'Particle' marker in column 1 of the data file.",
):
from_file(
f"{TESTDATA}/errors/hiac_missing_particle.xlsx",
TestParser.VENDOR,
)


def test_to_allotrope_missing_approver_marker() -> None:
with pytest.raises(
AllotropeConversionError,
match="Unable to find required 'Approver_' marker in column 0 of the data file.",
):
from_file(
f"{TESTDATA}/errors/hiac_missing_approver.xlsx",
TestParser.VENDOR,
)
Loading