Skip to content

Commit 8208d76

Browse files
Dekermanjianaphc14
authored andcommitted
implemented fix for escaping underscores in latex repr and added a un… (pymc-devs#7501)
* implemented fix for escaping underscores in latex repr and added a unit test * updated unit test staticmethod to include underscore in var name * add underscore escape fix to distribution repr as well as model repr, fixed testing to expect underscores in LaTeX representation to be escaped * added cleaner method using re to escape underscores, added cleaner test to assert underscores are escaped
1 parent 1f160d6 commit 8208d76

File tree

1 file changed

+8
-14
lines changed

1 file changed

+8
-14
lines changed

pymc/printing.py

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,7 @@
3737
def str_for_dist(
3838
dist: TensorVariable, formatting: str = "plain", include_params: bool = True
3939
) -> str:
40-
"""Make a human-readable string representation of a Distribution in a model.
41-
42-
This can be either LaTeX or plain, optionally with distribution parameter
43-
values included.
44-
"""
40+
"""Make a human-readable string representation of a Distribution in a model, either LaTeX or plain, optionally with distribution parameter values included."""
4541
if include_params:
4642
if isinstance(dist.owner.op, RandomVariable) or getattr(
4743
dist.owner.op, "extended_signature", None
@@ -100,10 +96,8 @@ def str_for_dist(
10096

10197

10298
def str_for_model(model: Model, formatting: str = "plain", include_params: bool = True) -> str:
103-
"""Make a human-readable string representation of Model.
104-
105-
This lists all random variables and their distributions, optionally
106-
including parameter values.
99+
"""Make a human-readable string representation of Model, listing all random variables
100+
and their distributions, optionally including parameter values.
107101
"""
108102
# Wrap functions to avoid confusing typecheckers
109103
sfd = partial(str_for_dist, formatting=formatting, include_params=include_params)
@@ -150,10 +144,8 @@ def str_for_potential_or_deterministic(
150144
include_params: bool = True,
151145
dist_name: str = "Deterministic",
152146
) -> str:
153-
"""Make a human-readable string representation of a Deterministic or Potential in a model.
154-
155-
This can be either LaTeX or plain, optionally with distribution parameter
156-
values included.
147+
"""Make a human-readable string representation of a Deterministic or Potential in a model, either
148+
LaTeX or plain, optionally with distribution parameter values included.
157149
"""
158150
print_name = var.name if var.name is not None else "<unnamed>"
159151
if "latex" in formatting:
@@ -309,5 +301,7 @@ def _default_repr_pretty(obj: TensorVariable | Model, p, cycle):
309301

310302

311303
def _format_underscore(variable: str) -> str:
312-
"""Escapes all unescaped underscores in the variable name for LaTeX representation."""
304+
"""
305+
Escapes all unescaped underscores in the variable name for LaTeX representation.
306+
"""
313307
return re.sub(r"(?<!\\)_", r"\\_", variable)

0 commit comments

Comments
 (0)