Skip to content

Commit 65dcb49

Browse files
authored
Return an empty string for empty model representation (#5577)
1 parent 4626712 commit 65dcb49

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

pymc/printing.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ def str_for_model(model: Model, formatting: str = "plain", include_params: bool
6262

6363
rv_reprs = [rv.str_repr(formatting=formatting, include_params=include_params) for rv in all_rv]
6464
rv_reprs = [rv_repr for rv_repr in rv_reprs if "TransformedDistribution()" not in rv_repr]
65+
66+
if not rv_reprs:
67+
return ""
6568
if "latex" in formatting:
6669
rv_reprs = [
6770
rv_repr.replace(r"\sim", r"&\sim &").strip("$")

pymc/tests/test_model.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -753,3 +753,7 @@ def test_deterministic():
753753

754754
assert model.y == y
755755
assert model["y"] == y
756+
757+
758+
def test_empty_model_representation():
759+
assert pm.Model().str_repr() == ""

0 commit comments

Comments
 (0)