-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Fix some type hinting to help with migrating Distribution
#7484
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
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #7484 +/- ##
==========================================
- Coverage 92.16% 92.16% -0.01%
==========================================
Files 103 103
Lines 17200 17203 +3
==========================================
+ Hits 15853 15855 +2
- Misses 1347 1348 +1
|
mypy is not happy with the changes? https://github.com/pymc-devs/pymc/actions/runs/10613016885/job/29415940076?pr=7484 |
Trying a solution, see below. Yes. That's this commit, where I fixed the incorrect type hint syntax. All three reported errors are the same:
and are due to class Censored(Distribution):
rv_type = CensoredRV
rv_op = CensoredRV.rv_op # <-- a method
class Normal(Distribution):
rv_op = NormalRV() # <-- an instance of NormalRV, which is a subclass of RandomVariable Solution |
sounds correct |
I am not going to worry about the error in I am currently testing if I can forego the |
The failing test is unrelated I guess? @ricardoV94 I think I'm finished with this one 😊 |
Then can you remove the type hints, we can't merge with a known failing CI or it will be a source of confusion for everyone else |
I can remove the type hint for class attribute class Foo:
bar |
Use of bound_arg_indices shows that this should be a (start, end) tuple, not a list.
I don't want to touch the `= None` part. I could add ` | None` to the type hint but I suspect the `= None` is unnecessary.
This is a bit like using a Protocol class, we say that whatever is passed to rv_op, it should return a TensorVariable.
I don't think these are necessary at all. The tests will tell us so.
334b232
to
157c29a
Compare
@ricardoV94 mind taking a look? |
pymc/distributions/distribution.py
Outdated
if class_change_dist_size is not None: | ||
raise ValueError("HAHAHA") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fun debug statement left :)
if class_change_dist_size is not None: | |
raise ValueError("HAHAHA") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hehe! That's what I get for not adding my changes line by line for this particular commit!
pymc/distributions/continuous.py
Outdated
@@ -152,7 +152,7 @@ class BoundedContinuous(Continuous): | |||
"""Base class for bounded continuous distributions""" | |||
|
|||
# Indices of the arguments that define the lower and upper bounds of the distribution | |||
bound_args_indices: list[int] | None = None | |||
bound_args_indices: tuple[int, int] | None = None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aren't there distributions with only one of the bounds (lower, upper)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, there are! I was wondering why mypy didn't flag it, but of course it was originally an error as list[int]
doesn't allow (3, None)
! Fixing this
Allows optional lower or upper bounds.
The failing tests stem from this commit, not this PR. |
@thomasaarholt should be fixed by #7529 |
Thanks @thomasaarholt |
Description
This is a small PR. I've added and fixed type hinting to a few lines of code. The idea is to make it easier to migrate the
Distribution
class to a function-based approach as discussed in the related issue.Related Issue
Checklist
Type of change
📚 Documentation preview 📚: https://pymc--7484.org.readthedocs.build/en/7484/