Skip to content

Add Docstrings for pymc.dims.distributions.scalar#8041

Merged
ricardoV94 merged 5 commits into
pymc-devs:mainfrom
MSK-005:docstrings/7861
Jan 22, 2026
Merged

Add Docstrings for pymc.dims.distributions.scalar#8041
ricardoV94 merged 5 commits into
pymc-devs:mainfrom
MSK-005:docstrings/7861

Conversation

@MSK-005
Copy link
Copy Markdown
Contributor

@MSK-005 MSK-005 commented Jan 5, 2026

Description

This PR (for #7861) adds a function create_scalar_dims_docstrings() that copies the docstrings from all relevant classes in pymc.distributions.continuous to pymc.dims.distributions.scalar, replacing "tensor_like" with "xtensor_like" where applicable.

Related Issue

  • Closes #7861
  • Related to #

Checklist

Type of change

  • New feature / enhancement
  • Bug fix
  • Documentation
  • Maintenance
  • Other (please specify):

@MSK-005 MSK-005 changed the title Added function to copy docstrings Add Docstrings for pymc.dims.distributions.scalar Jan 5, 2026
@MSK-005
Copy link
Copy Markdown
Contributor Author

MSK-005 commented Jan 8, 2026

@ricardoV94, looking forward to your code review.

Comment thread pymc/dims/distributions/scalar.py Outdated
Comment on lines +207 to +212
# 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
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small performance idea: I guess we can get dims_dists first and do a more targetted filter (matches name -> is a subclass of Distribution)?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@ricardoV94 ricardoV94 requested a review from OriolAbril January 13, 2026 17:12
@ricardoV94
Copy link
Copy Markdown
Member

Comment thread pymc/dims/distributions/scalar.py Outdated
return super().dist([alpha, beta], **kwargs)


def create_scalar_dims_docstrings():
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Went forward with the decorator approach. Also, pm.dims.Univariate.dist has no documentation. What do we do about that?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The dist method having no documentation? It's fine? They don't have in regular distributions either if I recall correctly

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's the dist() page for pm.Normal.dist: link

Here's the dist() page for pm.dims.Normal.dist: link

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's just showing the docstrings of the base class, nothing specific about the Normal dist

Comment thread pymc/dims/distributions/scalar.py Outdated
from pymc.distributions.continuous import HalfCauchyRV, HalfStudentTRV, flat, halfflat


def _copy_docstring(regular_cls):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes more sense to have this helper in pymc/dims/distributions/core.py?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread pymc/dims/distributions/scalar.py Outdated
Comment on lines +32 to +33
def _change_docstring_words(docstring):
return docstring.replace("tensor_like", "xtensor_like")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Sorry about that.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's nothing to apologize about

@ricardoV94
Copy link
Copy Markdown
Member

This is pretty sweet, thanks @MSK-005

@codecov
Copy link
Copy Markdown

codecov Bot commented Jan 21, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.81%. Comparing base (056e80c) to head (ba0d897).
⚠️ Report is 67 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            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     
Files with missing lines Coverage Δ
pymc/dims/distributions/core.py 90.00% <100.00%> (+0.44%) ⬆️
pymc/dims/distributions/scalar.py 95.62% <100.00%> (+0.74%) ⬆️

... and 23 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@MSK-005
Copy link
Copy Markdown
Contributor Author

MSK-005 commented Jan 21, 2026

@ricardoV94, thank you for your guidance. Truly a blessing. All tests pass. Also a blessing.
Will appear in more PRs, hopefully.

Copy link
Copy Markdown
Member

@OriolAbril OriolAbril left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@ricardoV94 ricardoV94 merged commit c2476b8 into pymc-devs:main Jan 22, 2026
42 checks passed
@welcome
Copy link
Copy Markdown

welcome Bot commented Jan 22, 2026

Congratulations Banner]
Congrats on merging your first pull request! 🎉 We here at PyMC are proud of you! 💖 Thank you so much for your contribution 🎁

@MSK-005 MSK-005 deleted the docstrings/7861 branch January 22, 2026 18:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants