Skip to content

Commit 3b849e6

Browse files
author
Release Manager
committed
gh-39556: Fixed issue where Partitions() was caching results when an error happens. Fixes #38640. Partition used to cache the result even when an error was given if provided with QQ instead of ZZ. To fix this we apply ZZ to convert our input into integers during normalization. This has the added side effect of making list(Partitions(4,parts_in=vector(QQ,[2,4]))) not produce an error as seen in the added doctest. However providing Partitions() with rational numbers that cannot be converted to integers does crash as expected. This crash does not cache the result however so the error is fixed. ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> - [X] The title is concise and informative. - [X] The description explains in detail what this PR is about. - [X] I have linked a relevant issue or discussion. - [X] I have created tests covering the changes. - [X] I have updated the documentation and checked the documentation preview. ### ⌛ Dependencies URL: #39556 Reported by: Noel-Roemmele Reviewer(s): Noel-Roemmele, Travis Scrimshaw
2 parents a6c8806 + 93c4fbb commit 3b849e6

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/sage/combinat/partition.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7596,8 +7596,19 @@ def __classcall_private__(cls, n, parts):
75967596
sage: P2 = Partitions(4, parts_in=(1,2))
75977597
sage: P is P2
75987598
True
7599+
7600+
Ensure that :issue:`38640` is fixed::
7601+
7602+
sage: list(Partitions(4,parts_in=vector(QQ,[2,4])))
7603+
[[4], [2, 2]]
7604+
sage: list(Partitions(4,parts_in=vector(QQ,[2,1/4])))
7605+
Traceback (most recent call last):
7606+
...
7607+
TypeError: no conversion of this rational to integer
7608+
sage: list(Partitions(4,parts_in=vector(ZZ,[2,4])))
7609+
[[4], [2, 2]]
75997610
"""
7600-
parts = tuple(sorted(parts))
7611+
parts = tuple(sorted(set(map(ZZ,parts))))
76017612
return super().__classcall__(cls, Integer(n), parts)
76027613

76037614
def __init__(self, n, parts):

0 commit comments

Comments
 (0)