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

IncidenceStructure breaks if points cannot be sorted #26938

Closed
jdemeyer opened this issue Dec 21, 2018 · 17 comments
Closed

IncidenceStructure breaks if points cannot be sorted #26938

jdemeyer opened this issue Dec 21, 2018 · 17 comments

Comments

@jdemeyer
Copy link

This sort can fail if the points are not comparable:

                sortkey = lambda e: [(0 if x is None else 2 if isinstance(x, str) else 1, x) for x in e]\
                    if isinstance(e, tuple) else e
                self._points = sorted(points, key=sortkey)

The sortkey tries to find a clever way to "sort" the points but hardcoding classes like that is not a general solution. In particular, it's still comparing integers and strings when #22029 is appplied.

Instead, just don't sort.

CC: @vinklein

Component: combinatorics

Author: Jeroen Demeyer

Branch/Commit: a354dc1

Reviewer: Frédéric Chapoton

Issue created by migration from https://trac.sagemath.org/ticket/26938

@jdemeyer jdemeyer added this to the sage-8.6 milestone Dec 21, 2018
@jdemeyer

This comment has been minimized.

@jdemeyer

This comment has been minimized.

@jdemeyer

This comment has been minimized.

@vinklein
Copy link
Mannequin

vinklein mannequin commented Dec 21, 2018

comment:4

A mix of points of strings type and integers type will not make this function fail.

This work in python3:

>>> (1, 3) < (2, 'a string')
True

The comparison stops if the first element of each tuple are different.

@vinklein
Copy link
Mannequin

vinklein mannequin commented Dec 21, 2018

comment:5

Also, the sortkey should be implemented as ordinary function def sortkey instead of this unreadable one-liner (why do people feel that a lambda is required to define a sorting key?).

Indeed, pep8 says so, my bad.

@jdemeyer
Copy link
Author

comment:6

Replying to @vinklein:

A mix of points of strings type and integers type will not make this function fail.

Apparently, it does. See the patchbot report on #22029. I have not looked at the details.

@jdemeyer
Copy link
Author

comment:7

On #22029, I do get

TypeError: unsupported operand parent(s) for >: 'Integer Ring' and '<type 'str'>'

and it's pointing to the line

self._points = sorted(points, key=sortkey)

@jdemeyer
Copy link
Author

@jdemeyer

This comment has been minimized.

@jdemeyer
Copy link
Author

Author: Jeroen Demeyer

@jdemeyer
Copy link
Author

Commit: a354dc1

@jdemeyer
Copy link
Author

New commits:

a354dc1Do not sort points in IncidenceStructure

@jdemeyer

This comment has been minimized.

@fchapoton
Copy link
Contributor

comment:11

ok, let it be

@fchapoton
Copy link
Contributor

Reviewer: Frédéric Chapoton

@embray
Copy link
Contributor

embray commented Jan 15, 2019

comment:12

Retarging tickets optimistically to the next milestone. If you are responsible for this ticket (either its reporter or owner) and don't believe you are likely to complete this ticket before the next release (8.7) please retarget this ticket's milestone to sage-pending or sage-wishlist.

@embray embray modified the milestones: sage-8.6, sage-8.7 Jan 15, 2019
@vbraun
Copy link
Member

vbraun commented Jan 23, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants