Repository: sagemath/sage

Issue:
DiGraph.radius fails for directed graphs with non-comparable vertices
### Is there an existing issue for this?

- [X] I have searched the existing issues for a bug report that matches the one I want to file, without success.

### Did you read the documentation and troubleshoot guide?

- [X] I have read the documentation and troubleshoot guide

### Environment

```markdown
- **OS**: Debian 11
- **Sage Version**: 3.11
```


### Steps To Reproduce

Calling the `radius` method on a DiGraph with non comparable vertices

### Expected Behavior

```python
sage: G = Graph([[42, 'John'], [(42, 'John')]])
sage: G.radius()
1
sage: H = DiGraph([[42, 'John'], [(42, 'John')]])
sage: H.radius()
1
```

### Actual Behavior

H.radius() raises the following exception
```python
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In [10], line 1
----> 1 H.radius()

File ~/src/sage-9.8/src/sage/graphs/digraph.py:2350, in DiGraph.radius(self, by_weight, algorithm, weight_function, check_weight)
   2347 if not self.order():
   2348     raise ValueError("radius is not defined for the empty DiGraph")
-> 2350 return min(self.eccentricity(v=None, by_weight=by_weight,
   2351                              weight_function=weight_function,
   2352                              check_weight=check_weight,
   2353                              algorithm=algorithm))

File ~/src/sage-9.8/src/sage/graphs/digraph.py:2252, in DiGraph.eccentricity(self, v, by_weight, algorithm, weight_function, check_weight, dist_dict, with_labels)
   2250         return dict(zip(v, eccentricity(self, algorithm=algo, vertex_list=v)))
   2251     else:
-> 2252         return eccentricity(self, algorithm=algo)
   2254 if algorithm in ['Floyd-Warshall-Python', 'Floyd-Warshall-Cython', 'Johnson_Boost']:
   2255     dist_dict = self.shortest_path_all_pairs(by_weight=by_weight, algorithm=algorithm,
   2256                                              weight_function=weight_function,
   2257                                              check_weight=False)[0]

File ~/src/sage-9.8/src/sage/graphs/distances_all_pairs.pyx:1051, in sage.graphs.distances_all_pairs.eccentricity()
   1049 cdef list int_to_vertex
   1050 if vertex_list is None:
-> 1051     int_to_vertex = G.vertices(sort=True)
   1052 elif len(vertex_list) == n and set(vertex_list) == set(G):
   1053     int_to_vertex = vertex_list

File ~/src/sage-9.8/src/sage/graphs/generic_graph.py:11268, in GenericGraph.vertices(self, sort, key, degree, vertex_property)
  11265     raise ValueError('sort keyword is False, yet a key function is given')
  11267 if sort:
> 11268     return sorted(self.vertex_iterator(degree=degree, vertex_property=vertex_property), key=key)
  11269 return list(self.vertex_iterator(degree=degree, vertex_property=vertex_property))

File ~/src/sage-9.8/src/sage/rings/integer.pyx:916, in sage.rings.integer.Integer.__richcmp__()
    914     c = mpz_cmp_d((<Integer>left).value, d)
    915 else:
--> 916     return coercion_model.richcmp(left, right, op)
    917 
    918 return rich_to_bool_sgn(op, c)

File ~/src/sage-9.8/src/sage/structure/coerce.pyx:2008, in sage.structure.coerce.CoercionModel.richcmp()
   2006     raise bin_op_exception('<=', x, y)
   2007 elif op == Py_GT:
-> 2008     raise bin_op_exception('>', x, y)
   2009 else:
   2010     raise bin_op_exception('>=', x, y)

TypeError: unsupported operand parent(s) for >: 'Integer Ring' and '<class 'str'>'
```

### Additional Information

Similar to https://github.com/sagemath/sage/issues/35168


Discussion:

Resolving patch:
diff --git a/src/sage/graphs/digraph.py b/src/sage/graphs/digraph.py
--- a/src/sage/graphs/digraph.py
+++ b/src/sage/graphs/digraph.py
@@ -2249,7 +2249,7 @@ def eccentricity(self, v=None, by_weight=False, algorithm=None,
                 if with_labels:
                     return dict(zip(v, eccentricity(self, algorithm=algo, vertex_list=v)))
                 else:
-                    return eccentricity(self, algorithm=algo)
+                    return eccentricity(self, algorithm=algo, vertex_list=v)
 
             if algorithm in ['Floyd-Warshall-Python', 'Floyd-Warshall-Cython', 'Johnson_Boost']:
                 dist_dict = self.shortest_path_all_pairs(by_weight=by_weight, algorithm=algorithm,
@@ -2343,11 +2343,17 @@ def radius(self, by_weight=False, algorithm=None, weight_function=None,
             Traceback (most recent call last):
             ...
             ValueError: radius is not defined for the empty DiGraph
+
+        Check that :trac:`35300` is fixed::
+
+            sage: H = DiGraph([[42, 'John'], [(42, 'John')]])
+            sage: H.radius()
+            1
         """
         if not self.order():
             raise ValueError("radius is not defined for the empty DiGraph")
 
-        return min(self.eccentricity(v=None, by_weight=by_weight,
+        return min(self.eccentricity(v=list(self), by_weight=by_weight,
                                      weight_function=weight_function,
                                      check_weight=check_weight,
                                      algorithm=algorithm))
@@ -2476,6 +2482,15 @@ def diameter(self, by_weight=False, algorithm=None, weight_function=None,
             3
             sage: G.diameter(algorithm='DiFUB', by_weight=True)
             3.0
+
+        Check that :trac:`35300` is fixed::
+
+            sage: H = DiGraph([[42, 'John'], [(42, 'John')]])
+            sage: H.diameter()
+            +Infinity
+            sage: H.add_edge('John', 42)
+            sage: H.diameter()
+            1
         """
         if not self.order():
             raise ValueError("diameter is not defined for the empty DiGraph")
@@ -2507,7 +2522,7 @@ def diameter(self, by_weight=False, algorithm=None, weight_function=None,
             from sage.graphs.distances_all_pairs import diameter
             return diameter(self, algorithm='standard')
 
-        return max(self.eccentricity(v=None, by_weight=by_weight,
+        return max(self.eccentricity(v=list(self), by_weight=by_weight,
                                      weight_function=weight_function,
                                      check_weight=False,
                                      algorithm=algorithm))


Test patch: