Skip to content

Commit 1139547

Browse files
committed
fixup
1 parent 1ffdc1f commit 1139547

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

petab/v1/math/printer.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class PetabStrPrinter(StrPrinter):
1010
"""A PEtab-compatible sympy string-printer."""
1111

1212
#: Mapping of sympy functions to PEtab functions
13-
func_map = {
13+
_func_map = {
1414
"asin": "arcsin",
1515
"acos": "arccos",
1616
"atan": "arctan",
@@ -51,7 +51,7 @@ def _print_Function(self, expr):
5151
if expr.func.__name__ == "Piecewise":
5252
return self._print_Piecewise(expr)
5353

54-
if func := self.func_map.get(expr.func.__name__):
54+
if func := self._func_map.get(expr.func.__name__):
5555
return f"{func}({', '.join(map(self._print, expr.args))})"
5656

5757
return super()._print_Function(expr)
@@ -61,7 +61,7 @@ def _print_Piecewise(self, expr):
6161
# merge the tuples and drop the final `True` condition
6262
str_args = map(
6363
self._print,
64-
islice(chain.from_iterable(expr.args), len(expr.args) - 1),
64+
islice(chain.from_iterable(expr.args), 2 * len(expr.args) - 1),
6565
)
6666
return f"piecewise({', '.join(str_args)})"
6767

@@ -81,8 +81,9 @@ def petab_math_str(expr: sp.Basic | sp.Expr | None) -> str:
8181
>>> expr = sp.sympify("x**2 + sin(y)")
8282
>>> petab_math_str(expr)
8383
'x ^ 2 + sin(y)'
84+
>>> expr = sp.sympify("Piecewise((1, x > 0), (0, True))")
8485
>>> petab_math_str(expr)
85-
'x ^ 2 + sin(y)'
86+
'piecewise(1, x > 0, 0)'
8687
"""
8788
if expr is None:
8889
return ""

0 commit comments

Comments
 (0)