Skip to content
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

allow incomparable labels in SetPartition #38974

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions src/sage/combinat/set_partition.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,11 @@
sage: S([[1,3],[2,4]])
{{1, 3}, {2, 4}}
"""
return '{' + ', '.join('{' + repr(sorted(x))[1:-1] + '}' for x in self) + '}'
try:
s = [sorted(x) for x in self]
except TypeError:
s = [sorted(x, key=str) for x in self]

Check warning on line 79 in src/sage/combinat/set_partition.py

View check run for this annotation

Codecov / codecov/patch

src/sage/combinat/set_partition.py#L78-L79

Added lines #L78 - L79 were not covered by tests
return '{' + ', '.join('{' + repr(x)[1:-1] + '}' for x in s) + '}'

def __hash__(self):
"""
Expand Down Expand Up @@ -532,7 +536,7 @@


class SetPartition(AbstractSetPartition,
metaclass=InheritComparisonClasscallMetaclass):
metaclass=InheritComparisonClasscallMetaclass):
r"""
A partition of a set.

Expand Down Expand Up @@ -620,7 +624,11 @@
{}
"""
self._latex_options = {}
ClonableArray.__init__(self, parent, sorted(map(frozenset, s), key=min), check=check)
try:
s = sorted(map(frozenset, s), key=min)
except TypeError:
s = sorted(map(frozenset, s), key=lambda b: min(str(b)))
ClonableArray.__init__(self, parent, s, check=check)

def check(self):
"""
Expand Down Expand Up @@ -2821,7 +2829,11 @@
sage: SetPartitions(["a", "b"]).list()
[{{'a', 'b'}}, {{'a'}, {'b'}}]
"""
for sp in set_partition_iterator(sorted(self._set)):
try:
s = sorted(self._set)
except TypeError:
s = sorted(self._set, key=str)

Check warning on line 2835 in src/sage/combinat/set_partition.py

View check run for this annotation

Codecov / codecov/patch

src/sage/combinat/set_partition.py#L2834-L2835

Added lines #L2834 - L2835 were not covered by tests
for sp in set_partition_iterator(s):
yield self.element_class(self, sp, check=False)

def base_set(self):
Expand Down Expand Up @@ -3179,7 +3191,11 @@
sage: SetPartitions(["a", "b", "c"], 2).list()
[{{'a', 'c'}, {'b'}}, {{'a'}, {'b', 'c'}}, {{'a', 'b'}, {'c'}}]
"""
for sp in set_partition_iterator_blocks(sorted(self._set), self._k):
try:
s = sorted(self._set)
except TypeError:
s = sorted(self._set, key=str)

Check warning on line 3197 in src/sage/combinat/set_partition.py

View check run for this annotation

Codecov / codecov/patch

src/sage/combinat/set_partition.py#L3196-L3197

Added lines #L3196 - L3197 were not covered by tests
for sp in set_partition_iterator_blocks(s, self._k):
yield self.element_class(self, sp, check=False)

def __contains__(self, x):
Expand Down
Loading