From 201c5d038891e39977553b6ee7eeaed14141830d Mon Sep 17 00:00:00 2001 From: Peter Corke Date: Tue, 13 Oct 2026 08:02:55 +1000 Subject: [PATCH 1/2] fix: Graph.__str__ separates thousands in its counts A graph of 4883 vertices now prints as 4,883 vertices, 8,392 edges, which is easier to read. Counts below 1,000 are as before. Co-Authored-By: Claude Sonnet 5.5 --- src/pgraph/PGraph.py | 4 +++- tests/test_graph.py | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/pgraph/PGraph.py b/src/pgraph/PGraph.py index ae0e02b7..fd4fb7c7 100644 --- a/src/pgraph/PGraph.py +++ b/src/pgraph/PGraph.py @@ -288,6 +288,8 @@ def __str__(self) -> str: :return: one-line summary of vertex/edge/component counts :rtype: str + Counts of 1,000 or more have thousands separators. + .. runblock:: pycon >>> from pgraph import UGraph @@ -301,7 +303,7 @@ def __str__(self) -> str: :seealso: :meth:`show` """ - s = f"{self.__class__.__name__}: {self.n} {'vertex' if self.n==1 else 'vertices'}, {self.ne} edge{'s'[:self.ne^1]}, {self.nc} component{'s'[:self.nc^1]}" + s = f"{self.__class__.__name__}: {self.n:,} {'vertex' if self.n==1 else 'vertices'}, {self.ne:,} edge{'s'[:self.ne^1]}, {self.nc:,} component{'s'[:self.nc^1]}" return s def __repr__(self) -> str: diff --git a/tests/test_graph.py b/tests/test_graph.py index f8d6204d..8110e165 100644 --- a/tests/test_graph.py +++ b/tests/test_graph.py @@ -51,6 +51,21 @@ def test_str(self): self.assertEqual(len(lines), 3) # class-name header + one line per vertex self.assertEqual(lines[0], "DGraph:") + + def test_str_has_thousands_separators(self): + # counts of 1,000 or more are easier to read with separators + g = UGraph() + vs = [g.add_vertex() for _ in range(1001)] + self.assertEqual(str(g), "UGraph: 1,001 vertices, 0 edges, 1,001 components") + for a, b in zip(vs, vs[1:]): + g.add_edge(a, b) + self.assertEqual(str(g), "UGraph: 1,001 vertices, 1,000 edges, 1 component") + # below a thousand it is as before + h = UGraph() + for _ in range(999): + h.add_vertex() + self.assertEqual(str(h), "UGraph: 999 vertices, 0 edges, 999 components") + def test_attr(self): g = UGraph() From 2a0aac2afc7bad93f74be8dc00492d54caf1a360 Mon Sep 17 00:00:00 2001 From: Peter Corke Date: Tue, 13 Oct 2026 08:56:09 +1000 Subject: [PATCH 2/2] tests: test_graph imports the names it uses Replaces the star import, which Codacy reports as F405 on every changed line that uses one of the names. Co-Authored-By: Claude Sonnet 5.5 --- tests/test_graph.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_graph.py b/tests/test_graph.py index 79c76134..c10df002 100644 --- a/tests/test_graph.py +++ b/tests/test_graph.py @@ -3,7 +3,7 @@ import numpy as np import numpy.testing as nt -from pgraph import * +from pgraph import DGraph, Edge, UGraph, Vertex class TestUGraph(unittest.TestCase):