rafguns / linkpred

Easy link prediction tool
Other
140 stars 46 forks source link

Error when nodes name are string type and int type #25

Closed dbvdb closed 5 years ago

dbvdb commented 5 years ago
def _sorted_tuple(t):
    a, b = t
    return (a, b) if a > b else (b, a)

TypeError: '>' not supported between instances of 'str' and 'int'
rafguns commented 5 years ago

Indeed, nodes are assumed to be all of the same type and sortable. Looking at this code again, I wonder if maybe we can just get rid of _sorted_tuple and do sth like this:

def __eq__(self, other):
    try:
        return self.elements == other.elements
    except AttributeError:
        a, b = other
        return self.elements == (a, b) or self.elements == (b, a)
rafguns commented 5 years ago

Fixed in 58ff2e1.

I have kept _sorted_tuple for now: it ensures that the ranking of node pairs is always the same, even in case of ties.