From a783cf6f9412679888e44e5a700b9a6396f5400d Mon Sep 17 00:00:00 2001 From: Haoran Du Date: Sun, 7 Jun 2026 23:47:08 +0800 Subject: [PATCH] Fix pytest baseline geometry nobe numpy issues --- easygraph/functions/drawing/geometry.py | 10 ++++++++-- easygraph/functions/structural_holes/NOBE.py | 4 ++++ easygraph/readwrite/gexf.py | 3 ++- easygraph/readwrite/graphml.py | 5 +++-- easygraph/readwrite/tests/test_graphml.py | 3 ++- 5 files changed, 19 insertions(+), 6 deletions(-) diff --git a/easygraph/functions/drawing/geometry.py b/easygraph/functions/drawing/geometry.py index 4e71dc63..8270191e 100644 --- a/easygraph/functions/drawing/geometry.py +++ b/easygraph/functions/drawing/geometry.py @@ -24,9 +24,15 @@ def vlen(vector): def common_tangent_radian(r1, r2, d): + if r1 < 0 or r2 < 0: + raise ValueError("Circle radii must be non-negative.") + if d <= 0 or d < abs(r2 - r1): + raise ValueError("No common tangent exists for the given circles.") value = abs(r2 - r1) / d - if value > 1.0: value = 1.0 - elif value < -1.0: value = -1.0 + if value > 1.0: + value = 1.0 + elif value < -1.0: + value = -1.0 alpha = math.acos(value) alpha = alpha if r1 > r2 else pi - alpha return alpha diff --git a/easygraph/functions/structural_holes/NOBE.py b/easygraph/functions/structural_holes/NOBE.py index 62f5f3f8..8be21c8f 100644 --- a/easygraph/functions/structural_holes/NOBE.py +++ b/easygraph/functions/structural_holes/NOBE.py @@ -40,6 +40,8 @@ def NOBE_SH(G, K, topk): raise ValueError("Embedding dimension K must be a positive integer.") if topk <= 0: raise ValueError("Parameter topk must be a positive integer.") + if G.number_of_nodes() == 0: + raise ValueError("NOBE_SH is not defined for an empty graph.") from sklearn.cluster import KMeans Y = eg.graph_embedding.NOBE(G, K) @@ -109,6 +111,8 @@ def NOBE_GA_SH(G, K, topk): raise ValueError("Embedding dimension K must be a positive integer.") if topk <= 0: raise ValueError("Parameter topk must be a positive integer.") + if G.number_of_nodes() == 0: + raise ValueError("NOBE_GA_SH is not defined for an empty graph.") from sklearn.cluster import KMeans Y = eg.NOBE_GA(G, K) diff --git a/easygraph/readwrite/gexf.py b/easygraph/readwrite/gexf.py index aea2edb6..650f2619 100644 --- a/easygraph/readwrite/gexf.py +++ b/easygraph/readwrite/gexf.py @@ -182,12 +182,13 @@ def construct_types(self): except ImportError: pass else: + np_float = getattr(np, "float_", np.float64) # prepend so that python types are created upon read (last entry wins) types = [ (np.float64, "float"), (np.float32, "float"), (np.float16, "float"), - (np.float_, "float"), + (np_float, "float"), (np.int_, "int"), (np.int8, "int"), (np.int16, "int"), diff --git a/easygraph/readwrite/graphml.py b/easygraph/readwrite/graphml.py index 8f577105..95cb2192 100644 --- a/easygraph/readwrite/graphml.py +++ b/easygraph/readwrite/graphml.py @@ -410,15 +410,16 @@ def construct_types(self): # These additions to types allow writing numpy types try: import numpy as np - except: + except ImportError: pass else: + np_float = getattr(np, "float_", np.float64) # prepend so that python types are created upon read (last entry wins) types = [ (np.float64, "float"), (np.float32, "float"), (np.float16, "float"), - (np.float_, "float"), + (np_float, "float"), (np.int_, "int"), (np.int8, "int"), (np.int16, "int"), diff --git a/easygraph/readwrite/tests/test_graphml.py b/easygraph/readwrite/tests/test_graphml.py index 6e4060ff..cf49d4dc 100644 --- a/easygraph/readwrite/tests/test_graphml.py +++ b/easygraph/readwrite/tests/test_graphml.py @@ -1283,7 +1283,8 @@ def test_mixed_int_type_number_attributes(self): def test_numpy_float(self): np = pytest.importorskip("numpy") - wt = np.float_(3.4) + np_float = getattr(np, "float_", np.float64) + wt = np_float(3.4) G = eg.Graph([(1, 2, {"weight": wt})]) fd, fname = tempfile.mkstemp() self.writer(G, fname)