Add Docstrings for pymc.dims.distributions.scalar#8041
Conversation
|
@ricardoV94, looking forward to your code review. |
| # Get all subclasses of Continuous class | ||
| imported_dists = { | ||
| name: cls | ||
| for name, cls in inspect.getmembers(_regular_dists, inspect.isclass) | ||
| if issubclass(cls, Continuous) and cls is not Continuous | ||
| } |
There was a problem hiding this comment.
Small performance idea: I guess we can get dims_dists first and do a more targetted filter (matches name -> is a subclass of Distribution)?
524a95c to
1958aaa
Compare
1958aaa to
f480347
Compare
| return super().dist([alpha, beta], **kwargs) | ||
|
|
||
|
|
||
| def create_scalar_dims_docstrings(): |
There was a problem hiding this comment.
Sorry to rethink again.
What if instead we use a decorator on the specific classes or manually do Univariate.__doc__ = foo(regular_dists.Univariate.__doc__)? So we don't need to loop and try to guess what goes with what. This also avoids accidentally overriding custom docstrings if we add them in the future.
There was a problem hiding this comment.
Went forward with the decorator approach. Also, pm.dims.Univariate.dist has no documentation. What do we do about that?
There was a problem hiding this comment.
The dist method having no documentation? It's fine? They don't have in regular distributions either if I recall correctly
There was a problem hiding this comment.
I think it's just showing the docstrings of the base class, nothing specific about the Normal dist
| from pymc.distributions.continuous import HalfCauchyRV, HalfStudentTRV, flat, halfflat | ||
|
|
||
|
|
||
| def _copy_docstring(regular_cls): |
There was a problem hiding this comment.
Makes more sense to have this helper in pymc/dims/distributions/core.py?
There was a problem hiding this comment.
Done. And I added a change_doc parameter that will replace "tensor_like" with "xtensor_like". The purpose was to provide flexibility if you want to modify docstrings before you copy them.
| def _change_docstring_words(docstring): | ||
| return docstring.replace("tensor_like", "xtensor_like") |
There was a problem hiding this comment.
still think it should be in core.py. Also let's leave the argument flexibility for when we actually need it (which may be never). It's an internal function so we don't need to worry about changing API
There was a problem hiding this comment.
Done. Sorry about that.
There was a problem hiding this comment.
There's nothing to apologize about
|
This is pretty sweet, thanks @MSK-005 |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #8041 +/- ##
==========================================
- Coverage 91.44% 90.81% -0.64%
==========================================
Files 116 121 +5
Lines 19002 19447 +445
==========================================
+ Hits 17377 17660 +283
- Misses 1625 1787 +162
🚀 New features to boost your workflow:
|
|
@ricardoV94, thank you for your guidance. Truly a blessing. All tests pass. Also a blessing. |
OriolAbril
left a comment
There was a problem hiding this comment.
Looks great!
Two nits which can perfectly be tackled in a future PR would be adding xtensor_like to the glossary like tensor_like and to the type aliases.
Sources for these two things: https://github.com/pymc-devs/pymc/blob/main/docs/source/glossary.md and variable numpydoc_xref_aliases of https://github.com/pymc-devs/pymc/blob/main/docs/source/conf.py#L63

Description
This PR (for #7861) adds a function
create_scalar_dims_docstrings()that copies the docstrings from all relevant classes inpymc.distributions.continuoustopymc.dims.distributions.scalar, replacing "tensor_like" with "xtensor_like" where applicable.Related Issue
Checklist
Type of change