#20499: Graphs: docstring of _add_ conflicts with function
--------------------------------+--------------------------
       Reporter:  jmantysalo    |        Owner:
           Type:  defect        |       Status:  needs_info
       Priority:  major         |    Milestone:  sage-7.2
      Component:  graph theory  |   Resolution:
       Keywords:                |    Merged in:
        Authors:                |    Reviewers:
Report Upstream:  N/A           |  Work issues:
         Branch:                |       Commit:
   Dependencies:                |     Stopgaps:
--------------------------------+--------------------------

Comment (by mcognetta):

 Replying to [comment:2 dcoudert]:
 > The current implementation of the `add` method is
 > {{{
 >         if isinstance(other_graph, GenericGraph):
 >             return self.disjoint_union(other_graph, labels='integers')
 > }}}
 > So it forces to relabel vertices as integer in `[0..n-1]`.
 >
 > At the least, we should raise an error for cases such as
 `Graph({0:[]})+'junk'`. Indeed, the other ordering raises an error
 > {{{
 > sage: 'junk'+Graph({0:[]})
 >
 ---------------------------------------------------------------------------
 > TypeError                                 Traceback (most recent call
 last)
 > <ipython-input-99-2e66a308aaff> in <module>()
 > ----> 1 'junk'+Graph({Integer(0):[]})
 >
 > TypeError: cannot concatenate 'str' and 'Graph' objects
 > }}}
 >
 > Now, the semantic of `+` is the disjoint union, and I believe this is
 the right choice.
 > We should however ensure that the doc of `__add__`, `disjoint_union`,
 `union`, `__mul__` and may be `join`, are clear enough and without
 ambiguity for users.
 >
 > Concerning the relabel to integers part, I agree that this is often
 painful. We could propose and intermediate behavior like: relabel only if
 some vertices have same label. But again some people will complain.
 >
 > David.

 I like the idea of only relabeling (the entire graph) if there are common
 vertices. NetworkX automatically relabels everything to integers when
 adding graphs and they get along fine without people complaining. We could
 possibly think about doing something with recording the previously named
 values when relabeling them. That way people could choose to invert the
 labeling if it was really necessary. Our add function could pass in a
 dictionary of the previous labels as an attribute in the newly created
 graph.
 In the end, I think that relabeling to integers is best. If people know
 they need to preserve vertex names, they can take precautions beforehand.

--
Ticket URL: <http://trac.sagemath.org/ticket/20499#comment:7>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica, 
and MATLAB

-- 
You received this message because you are subscribed to the Google Groups 
"sage-trac" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sage-trac.
For more options, visit https://groups.google.com/d/optout.

Reply via email to