Skip to content

Fix print name of LogitNormal and DiscreteWeibull#7935

Merged
ricardoV94 merged 4 commits into
pymc-devs:mainfrom
aloctavodia:print_name
Oct 23, 2025
Merged

Fix print name of LogitNormal and DiscreteWeibull#7935
ricardoV94 merged 4 commits into
pymc-devs:mainfrom
aloctavodia:print_name

Conversation

@aloctavodia
Copy link
Copy Markdown
Member

@aloctavodia aloctavodia commented Oct 23, 2025

dist.owner.op._print_name[0] was returning incorrect names for:

  • DiscreteWibull and LogitNormal, as they did not follow the conventions used for the rest of the distributions
  • ChiSquared was returning "Gamma", because it's implemented as a special case of Gamma.

Not sure if there is a simpler way to fix the issue for ChiSquared.


📚 Documentation preview 📚: https://pymc--7935.org.readthedocs.build/en/7935/

Comment thread pymc/distributions/continuous.py Outdated


class ChiSquared:
class ChiSquaredRV(RandomVariable):
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.

We shouldn't add more Ops just for naming. Less Ops means we can sample in other backends / do rewrites with fewer building blocks

Copy link
Copy Markdown
Member Author

@aloctavodia aloctavodia Oct 23, 2025

Choose a reason for hiding this comment

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

In the last commit ok?

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.

Nope, that's just a temporary hack. As soon as you do something like model.copy(), or any other model transform it's going to be lost. Why do you need it to show up as ChiSquared in the graphviz?

It's just a parametrization. Similarly we don't write UnitNormal if it happens to have loc=0, scale=1, even if we offered a helper to create them?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I was creating a pymc_to_preliz function with the inmediate goal of being able to call pz.plot() for both preliz and pymc distributions. I found this and assumed it was of broader interest to show proper names. But if not, I can try to solve it inside that function.

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 don't think naming should come at the cost of more code complexity/redundancy. This is just a helper that creates a specific Gamma and seems sensible to write it as such. Can't you call pz.plot on the gamma object that's returned?

PS: We can emphasize more in the docstrings that this is just a helper that return a regular Gamma distribution

Copy link
Copy Markdown
Member Author

@aloctavodia aloctavodia Oct 23, 2025

Choose a reason for hiding this comment

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

Yes, the call to pz.plot works fine. Because the ChiSquared is correctly converted into a Gamma PreliZ distribution, and then everything works. The only "issue" is that the result is a Gamma and not a ChiSquared. So this was more about avoiding potential confusion on the user side than fixing something not working.

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.

Do you want to add a comment to reduce confusion for future devs/users?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Added. I will also add a note on the PreliZ side.

@codecov
Copy link
Copy Markdown

codecov Bot commented Oct 23, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.33%. Comparing base (c7222f0) to head (b5f387e).
⚠️ Report is 59 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #7935      +/-   ##
==========================================
- Coverage   91.47%   89.33%   -2.15%     
==========================================
  Files         116      116              
  Lines       18904    18904              
==========================================
- Hits        17292    16887     -405     
- Misses       1612     2017     +405     
Files with missing lines Coverage Δ
pymc/distributions/continuous.py 98.25% <100.00%> (ø)
pymc/distributions/discrete.py 68.29% <100.00%> (-31.13%) ⬇️

... and 13 files with indirect coverage changes

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

@ricardoV94 ricardoV94 changed the title fix _print_name Fix print name of LogitNormal and DiscreteWeibull Oct 23, 2025
@ricardoV94 ricardoV94 merged commit 3c42a18 into pymc-devs:main Oct 23, 2025
22 of 23 checks passed
@aloctavodia aloctavodia deleted the print_name branch October 23, 2025 12:33
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.

2 participants