-
-
Notifications
You must be signed in to change notification settings - Fork 654
Fix discrepancy in partitions between provided number and starting partition #35582
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
I don't think this is the correct fix as the input is valid. It should either:
I am leaning towards (1) as it is easier to implement and most people only intend to compare partitions of the same size. However, (2) fits with what the doc says and lex order makes sense for all partitions (which is useful to do sometimes). |
It looks like (2) is in keeping with what the
For consistency's sake, I'll do (2). |
Another bug with the current approach:
|
Indeed, it seems like we should go with (2); good find. |
It wasn't too bad to fix - I just had to change the |
Actually I think there is still a logical mistake I'm making. It only makes sense to have For example, |
Right. I believe you can just add the trailing 1s, then return the next partition in lex order as the starting partition. |
Ah right that makes sense. I think its good now. I did also notice the following issue:
I think this should be an empty list. I think I can fix it by adding an |
You shouldn't need the if self._ending and self.n <= self._ending[0] and not (self.n == self._ending[0] and len(self._ending) == 1):
return None Although it is up to you if you want do it here or on a separate PR. |
When I try to do that, I get the following test failing:
I had the same issue with the |
Ah, we just need to make a small additional modification to f = self.first()
while not (f is None or f is False):
yield f
try:
f = self.next(f)
except (TypeError, ValueError):
f = None I also cleaned up the implementation a bit. Now if |
Ah awesome thanks. Changes are made and ready for review. |
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.
Thanks. Just two last little details.
Documentation preview for this PR is ready! 🎉 |
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.
Thank you. LGTM.
📚 Description
The behavior of
Partitions(n, starting=mu)
is confusing. It iterates over partitions starting withmu
, but it is not required thatmu
be a partition ofn
. For example:These are partitions of
4
not of5
. The change is to add aValueError
inPartitions_starting
to assert thatn
must agree with the weight of
mu
.The example above was drawn from the tests, so a few tests are changed so that they now pass.
📝 Checklist
⌛ Dependencies