File tree Expand file tree Collapse file tree 4 files changed +11
-4
lines changed
Expand file tree Collapse file tree 4 files changed +11
-4
lines changed Original file line number Diff line number Diff 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 )
Original file line number Diff line number Diff line change 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 ):
Original file line number Diff line number Diff line change @@ -34,6 +34,7 @@ def test_assumptions():
3434
3535
3636def test_printer ():
37+ assert petab_math_str (None ) == ""
3738 assert petab_math_str (BooleanTrue ()) == "true"
3839 assert petab_math_str (BooleanFalse ()) == "false"
3940
Original file line number Diff line number Diff 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 )
You can’t perform that action at this time.
0 commit comments