Skip to content

Commit 9ad05c1

Browse files
committed
prettify repr
1 parent 0a63f99 commit 9ad05c1

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

petab/v1/distributions.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ def _log(self, x: np.ndarray | float) -> np.ndarray | float:
109109
"""
110110
if self._logbase is False:
111111
return x
112-
return np.log(x) / np.log(self._logbase)
112+
with np.errstate(invalid="ignore", divide="ignore"):
113+
return np.log(x) / np.log(self._logbase)
113114

114115
def sample(self, shape=None) -> np.ndarray | float:
115116
"""Sample from the distribution.
@@ -306,9 +307,16 @@ def __init__(
306307
super().__init__(log=log, trunc=trunc)
307308

308309
def __repr__(self):
310+
if self._logbase is False:
311+
log = ""
312+
if self._logbase == np.exp(1):
313+
log = ", log=True"
314+
else:
315+
log = f", log={self._logbase}"
316+
309317
trunc = f", trunc={self._trunc}" if self._trunc else ""
310-
log = f", log={self._logbase}" if self._logbase else ""
311-
return f"Normal(loc={self._loc}, scale={self._scale}{trunc}{log})"
318+
319+
return f"Normal(loc={self._loc}, scale={self._scale}{log}{trunc})"
312320

313321
def _sample(self, shape=None) -> np.ndarray | float:
314322
return np.random.normal(loc=self._loc, scale=self._scale, size=shape)

0 commit comments

Comments
 (0)