-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor _repr_latex functionality #4065
Conversation
Co-authored-by: Thomas Wiecki <[email protected]>
Codecov Report
@@ Coverage Diff @@
## master #4065 +/- ##
==========================================
+ Coverage 86.83% 88.47% +1.64%
==========================================
Files 88 88
Lines 14165 13860 -305
==========================================
- Hits 12300 12263 -37
+ Misses 1865 1597 -268
|
@twiecki @ColCarroll I think this is ready for review. (Note the low diff test coverage is due to the many |
Apologies for missing this. It seems like an elegant way of making this maintainable, and I really like it. My only suggestion is to avoid default arguments and **kwargs in private methods ( That's not a big deal, though -- feel free to just say "that'd be too hard" rather than needing to explain why! I can take a second look and merge tonight in any case. |
I had not thought of that; in general, I think my style is basically "always use **kwargs and defaults whenever possible". But I think the static type checking is a good argument, definitely against using **kwargs throughout. I'll see whether I can change this easily in a next PR. |
This PR is the first step towards better overall string representations of PyMC3 objects, see #3956.
Before this PR, many distributions and other objects define their own
_repr_latex
functionality (generation of LaTeX-based string renderings for display in e.g. Jupyter notebooks). This functionality is almost entirely shared among all distributions, so this PR refactors it into one generic functionDistribution._str_repr
. The representation is based on the name of the distribution (_distr_name_for_repr()
), as well as a list of parameters relevant for the distribution (_distr_parameters_for_repr()
, e.g.mu
andsigma
for normal). These can be overridden by subclasses (and are in several cases, see code), but default values are the distribution's class name and the list of parameters in__init__
.Note that this PR already has a small amount of code for plain (as opposed to LaTeX) string representations in
_str_repr
; this is for future use, as described in #3956. This is not yet exposed (but the plan is to expose it later via the standard__str__
).