Skip to content

Commit

Permalink
support incomparable labels
Browse files Browse the repository at this point in the history
  • Loading branch information
mantepse committed Nov 16, 2024
1 parent 1b3f398 commit def85c5
Showing 1 changed file with 21 additions and 5 deletions.
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 @@ def _repr_(self):
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 @@ def pre_conjugate(sp):


class SetPartition(AbstractSetPartition,
metaclass=InheritComparisonClasscallMetaclass):
metaclass=InheritComparisonClasscallMetaclass):
r"""
A partition of a set.
Expand Down Expand Up @@ -620,7 +624,11 @@ def __init__(self, parent, s, check=True):
{}
"""
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 @@ def __iter__(self):
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 @@ def __iter__(self):
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

0 comments on commit def85c5

Please sign in to comment.