Skip to content

Commit 1ffdc1f

Browse files
committed
..
1 parent 22cbd2b commit 1ffdc1f

File tree

4 files changed

+11
-4
lines changed

4 files changed

+11
-4
lines changed

petab/v1/math/printer.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,17 @@ def _print_Max(self, expr):
7474
return f"max({', '.join(map(self._print, expr.args))})"
7575

7676

77-
def petab_math_str(expr: sp.Expr) -> str:
77+
def petab_math_str(expr: sp.Basic | sp.Expr | None) -> str:
7878
"""Convert a sympy expression to a PEtab-compatible math expression string.
7979
8080
:example:
8181
>>> expr = sp.sympify("x**2 + sin(y)")
8282
>>> petab_math_str(expr)
8383
'x ^ 2 + sin(y)'
84+
>>> petab_math_str(expr)
85+
'x ^ 2 + sin(y)'
8486
"""
87+
if expr is None:
88+
return ""
8589

8690
return PetabStrPrinter().doprint(expr)

petab/v1/math/sympify.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
__all__ = ["sympify_petab"]
1414

1515

16-
def sympify_petab(expr: str | int | float) -> sp.Expr | sp.Basic:
16+
def sympify_petab(expr: str | int | float | sp.Basic) -> sp.Expr | sp.Basic:
1717
"""Convert PEtab math expression to sympy expression.
1818
1919
.. note::
@@ -32,7 +32,7 @@ def sympify_petab(expr: str | int | float) -> sp.Expr | sp.Basic:
3232
The sympy expression corresponding to `expr`.
3333
Boolean values are converted to numeric values.
3434
"""
35-
if isinstance(expr, sp.Expr):
35+
if isinstance(expr, sp.Basic):
3636
return sympify_petab(petab_math_str(expr))
3737

3838
if isinstance(expr, int) or isinstance(expr, np.integer):

tests/v1/math/test_math.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ def test_assumptions():
3434

3535

3636
def test_printer():
37+
assert petab_math_str(None) == ""
3738
assert petab_math_str(BooleanTrue()) == "true"
3839
assert petab_math_str(BooleanFalse()) == "false"
3940

tests/v2/test_problem.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,9 @@ def test_modify_problem():
133133
}
134134
).set_index([OBSERVABLE_ID])
135135
assert_frame_equal(
136-
problem.observable_df[[OBSERVABLE_FORMULA, NOISE_FORMULA]],
136+
problem.observable_df[[OBSERVABLE_FORMULA, NOISE_FORMULA]].map(
137+
lambda x: float(x) if x != "" else None
138+
),
137139
exp_observable_df,
138140
check_dtype=False,
139141
)

0 commit comments

Comments
 (0)