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
6 changes: 6 additions & 0 deletions src/allotropy/parsers/bmg_mars/bmg_mars_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import pandas as pd

from allotropy.exceptions import AllotropeConversionError
from allotropy.named_file_contents import NamedFileContents
from allotropy.parsers.lines_reader import CsvReader, read_to_lines
from allotropy.parsers.utils.pandas import read_csv, SeriesData
Expand All @@ -27,6 +28,11 @@ def __init__(self, named_file_contents: NamedFileContents) -> None:
axis="index"
)
new = df["value"].str.split(": ", expand=True, n=1)

# Handle the case where no ": " delimiter is found, resulting in a DataFrame with only one column
if new.shape[1] < 2:
msg = "Unable to parse header data: no key-value pairs found with expected format."
raise AllotropeConversionError(msg)
self.header = SeriesData(pd.Series(new[1].values, index=new[0].str.upper()))

# Read in the rest of the file as a dataframe
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
User = USER,Path = C:\Program Files (x86)\BMG\PHERAstar\User\Data,Test run no. = 1,,,,,,,,,,,,,,,,,,,,,,
Test name = 472 QC 384 FI,Date = 03/03/2016,Time = 13:25:45,,,,,,,,,,,,,,,,,,,,,,
,,,,,,,,,,,,,,,,,,,,,,,,
ID1 = 472-0016,,,,,,,,,,,,,,,,,,,,,,,,
Fluorescence (FI),,,,,,,,,,,,,,,,,,,,,,,,
,,,,,,,,,,,,,,,,,,,,,,,,
Raw Data (485/520),,,,,,,,,,,,,,,,,,,,,,,,
,,,,,,,,,,,,,,,,,,,,,,,,
,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24
A,23864,23796,23934,,,,,,,,,231438,228111,,,,,,,,,24069,24096,24098
B,23774,23887,23810,,,,,,,,,229790,230207,,,,,,,,,24121,24223,24106
C,23879,23687,23567,,,,,,,,,2682,2677,,,,,,,,,24171,24104,23987
D,,,,,,,,,,,,2679,2661,,,,,,,,,,,
E,,,,,,,,,,,,371,374,,,,,,,,,,,
F,,,,,,,,,,,,372,375,,,,,,,,,,,
G,,,,,,,,,,,,187,183,,,,,,,,,,,
H,,,,,,,,,,,,187,188,,,,,,,,,,,
I,,,,,,,,,,,,123,118,,,,,,,,,,,
J,,,,,,,,,,,,120,120,,,,,,,,,,,
K,,,,,,,,,,,,120,124,,,,,,,,,,,
L,,,,,,,,,,,,122,121,,,,,,,,,,,
M,,,,,,,,,,,,119,121,,,,,,,,,,,
N,23478,23579,23326,,,,,,,,,118,120,,,,,,,,,23650,23767,23705
O,23730,23719,23988,,,,,,,,,122,121,,,,,,,,,23904,23959,24076
P,23488,23724,23895,,,,,,,,,120,120,,,,,,,,,23715,23502,23949
19 changes: 19 additions & 0 deletions tests/parsers/bmg_mars/to_allotrope_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,25 @@
import pytest

from allotropy.constants import CHARDET_ENCODING
from allotropy.exceptions import AllotropeConversionError
from allotropy.parser_factory import Vendor
from allotropy.testing.utils import from_file, get_testdata_dir
from tests.to_allotrope_test import ParserTest

TESTDATA = get_testdata_dir(__file__)


class TestParser(ParserTest):
VENDOR = Vendor.BMG_MARS


def test_to_allotrope_unsupported_kinetic_file() -> None:
with pytest.raises(
AllotropeConversionError,
match="Unable to parse header data: no key-value pairs found with expected format.",
):
from_file(
f"{TESTDATA}/errors/file_with_no_delimiter_malformed.csv",
TestParser.VENDOR,
encoding=CHARDET_ENCODING,
)
Loading