Skip to content

Commit b772194

Browse files
committed
Improve measurement data check in to_pandas
Replaces the simple measurement existence check in to_pandas with a new _has_measurement_data function that verifies species data is present. This prevents returning dataframes for measurements lacking actual data.
1 parent 85611cb commit b772194

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

pyenzyme/tabular.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def to_pandas(
3939
ValueError: If the measurement does not contain species data.
4040
"""
4141

42-
if not enzmldoc.measurements:
42+
if not _has_measurement_data(enzmldoc):
4343
return None
4444

4545
if ignore is None:
@@ -69,6 +69,15 @@ def to_pandas(
6969
return pd.DataFrame()
7070

7171

72+
def _has_measurement_data(enzmldoc: EnzymeMLDocument) -> bool:
73+
"""Checks if the measurement contains species data."""
74+
for meas in enzmldoc.measurements:
75+
for meas_data in meas.species_data:
76+
if meas_data.data is not None and len(meas_data.data) > 0:
77+
return True
78+
return False
79+
80+
7281
def read_excel(
7382
path: pl.Path | str,
7483
data_unit: str,
@@ -330,7 +339,6 @@ def _validate_measurement(meas: Measurement) -> None:
330339
"""Validates a Measurement object"""
331340

332341
# Check if the length of time is consistent
333-
334342
try:
335343
times = pd.DataFrame(
336344
{

0 commit comments

Comments
 (0)