Opened 2 years ago

Closed 2 years ago

Last modified 2 years ago

#27339 closed enhancement (duplicate)

Bug with (Di)Graph.edges()

Reported by: mercatp Owned by:
Priority: major Milestone: sage-duplicate/invalid/wontfix
Component: graph theory Keywords:
Cc: tscrim, chapoton, jhpalmieri, jdemeyer Merged in:
Authors: Reviewers:
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Status badges

Description (last modified by dcoudert)

DiGraph?.edges() fail for some examples because it try to sort but does not succed. For example:

sage: g = DiGraph([(0,1,0),(0,1,'a')], multiedges=True)
sage: g.edges()

raise an error. I suggest to remove the default value sort=True for this method to avoid this problem. Or, the exception raised by this sort could be catched and we return the list without sorting it if it is not sortable.

EDIT: the problem is everywhere

sage: g = Graph([(0,1,0),(0,1,'a')], multiedges=True)
sage: g.edges()
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-11-28c80235613c> in <module>()
----> 1 g.edges()

/Users/dcoudert/sage/local/lib/python2.7/site-packages/sage/graphs/generic_graph.pyc in edges(self, labels, sort, key)
  11066         L = list(self.edge_iterator(labels=labels))
  11067         if sort:
> 11068             L.sort(key=key)
  11069         return L
  11070 

/Users/dcoudert/sage/local/lib/python2.7/site-packages/sage/rings/integer.pyx in sage.rings.integer.Integer.__richcmp__ (build/cythonized/sage/rings/integer.c:7673)()
    948             c = mpz_cmp_d((<Integer>left).value, d)
    949         else:
--> 950             return coercion_model.richcmp(left, right, op)
    951 
    952         return rich_to_bool_sgn(op, c)

/Users/dcoudert/sage/local/lib/python2.7/site-packages/sage/structure/coerce.pyx in sage.structure.coerce.CoercionModel.richcmp (build/cythonized/sage/structure/coerce.c:19580)()
   1965         # so we raise an exception.
   1966         if op == Py_LT:
-> 1967             raise bin_op_exception('<', x, y)
   1968         elif op == Py_LE:
   1969             raise bin_op_exception('<=', x, y)

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

Change History (11)

comment:1 Changed 2 years ago by mercatp

  • Description modified (diff)

comment:2 Changed 2 years ago by mercatp

  • Description modified (diff)

comment:3 follow-up: Changed 2 years ago by dcoudert

  • Cc tscrim chapoton jhpalmieri jdemeyer added
  • Description modified (diff)
  • Summary changed from Bug with DiGraph.edges() to Bug with (D)iGraph.edges()

The problem is everywhere (I have edited the ticket description accordingly) and I'm surprised it has not been detected by any doctest...

It could be a side effect of recent changes in the coercion / richcmp model ?

I'm ccing many people because it seems a serious issue.

comment:4 Changed 2 years ago by tscrim

Yes, this looks like it is from #22029, which makes the behavior in Sage closer to that of Python3. So this is bringing more to the front the Python3 issues with graphs.

comment:5 Changed 2 years ago by jdemeyer

  • Milestone changed from sage-8.7 to sage-duplicate/invalid/wontfix
  • Resolution set to duplicate
  • Status changed from new to closed

Duplicate of #22349.

comment:6 in reply to: ↑ 3 ; follow-up: Changed 2 years ago by jdemeyer

Replying to dcoudert:

I'm surprised it has not been detected by any doctest...

Not many doctests mix types like that. The few ones that do apparently don't call vertices() or edges().

comment:7 Changed 2 years ago by dcoudert

Sorry, but I don't see why this ticket is duplicate of #22349. For me we have a new bug with python2. It's independent of the will to stop sorting vertices/edges.

comment:8 Changed 2 years ago by tscrim

I agree with Jeroen, it is effectively the same issue as #22349 except for a smaller set of objects (Python2 still allows you to compare an int and str).

comment:9 in reply to: ↑ 6 Changed 2 years ago by dcoudert

Not many doctests mix types like that. The few ones that do apparently don't call vertices() or edges().

We changed many many doctests for py3, certainly hiding the issue.

(Python2 still allows you to compare an int and str).

But now .vertices() and .edges() in Python2 don't...

comment:10 Changed 2 years ago by tscrim

At least the example in this ticket is an Integer (which is not an int) and a str comparison.

comment:11 Changed 2 years ago by slelievre

  • Summary changed from Bug with (D)iGraph.edges() to Bug with (Di)Graph.edges()
Note: See TracTickets for help on using tickets.