Skip to content

Commit

Permalink
fix units not recognized
Browse files Browse the repository at this point in the history
  • Loading branch information
JR-1991 committed Sep 24, 2024
1 parent 91b9993 commit de446b6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
15 changes: 14 additions & 1 deletion pyenzyme/sbml/serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,10 @@ def to_sbml(
sbmldoc = libsbml.SBMLDocument()
model = sbmldoc.createModel()
model.setName(doc.name)
units = _assign_ids_to_units(tools.find_unique(doc, UnitDefinition))
units = _assign_ids_to_units(tools.find_unique(doc, pe.UnitDefinition))

# Add units that have been defined by the custom UnitDefinition
convert_unit_classes(doc, units)

print_warnings = verbose

Expand Down Expand Up @@ -109,6 +112,16 @@ def to_sbml(
logger.info(f"OMEX archive written to {out}")


def convert_unit_classes(doc: pe.EnzymeMLDocument, custom_units: list[UnitDefinition]):
custom_units.extend(
[
pe.UnitDefinition(**unit.model_dump())
for unit in _assign_ids_to_units(tools.find_unique(doc, pe.UnitDefinition))
if unit.id not in [unit.id for unit in custom_units]
]
)


def _add_unit_definitions(unit: UnitDefinition):
"""Add unit definitions to the SBML model."""

Expand Down
5 changes: 4 additions & 1 deletion pyenzyme/tabular.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ def to_pandas(
df["id"] = [meas.id] * len(df)
dfs.append(df)

return pd.concat(dfs, ignore_index=True).reset_index(drop=True)
if dfs:
return pd.concat(dfs, ignore_index=True).reset_index(drop=True)
else:
return pd.DataFrame()


def read_excel(
Expand Down

0 comments on commit de446b6

Please sign in to comment.