From 1ef8e0c4a7fe58f904f6d5c22dc99149a1e970be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20F=2E=20Pereira?= Date: Thu, 21 Nov 2024 10:48:57 -0800 Subject: [PATCH 1/2] Fix from_spharapy naming in SimplicialComplex --- test/classes/test_simplicial_complex.py | 6 +++--- toponetx/classes/simplicial_complex.py | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/test/classes/test_simplicial_complex.py b/test/classes/test_simplicial_complex.py index f41367aa..d1ec01f5 100644 --- a/test/classes/test_simplicial_complex.py +++ b/test/classes/test_simplicial_complex.py @@ -1096,12 +1096,12 @@ def test_normalized_laplacian_matrix(self): @pytest.mark.skipif( tm is None, reason="Optional dependency 'spharapy' not installed." ) - def test_from_spharpy(self): - """Test the from_spharpy method of SimplicialComplex (support for spharpy trimesh).""" + def test_from_spharapy(self): + """Test the from_spharapy method of SimplicialComplex (support for spharapy trimesh).""" mesh = tm.TriMesh( [[0, 1, 2]], [[1.0, 0.0, 0.0], [0.0, 2.0, 0.0], [0.0, 0.0, 3.0]] ) - SC = SimplicialComplex.from_spharpy(mesh) + SC = SimplicialComplex.from_spharapy(mesh) simplices = SC.simplices assert len(simplices) == 7 assert [0, 1, 2] in simplices diff --git a/toponetx/classes/simplicial_complex.py b/toponetx/classes/simplicial_complex.py index 66a3a4eb..3be9bd81 100644 --- a/toponetx/classes/simplicial_complex.py +++ b/toponetx/classes/simplicial_complex.py @@ -1401,7 +1401,7 @@ def get_all_maximal_simplices(self): return [tuple(s) for s in self.simplices if self.is_maximal(s)] @classmethod - def from_spharpy(cls, mesh) -> Self: + def from_spharapy(cls, mesh) -> Self: """Import from sharpy. Parameters @@ -1423,7 +1423,7 @@ def from_spharpy(cls, mesh) -> Self: ... [[0, 1, 2]], [[1.0, 0.0, 0.0], [0.0, 2.0, 0.0], [0.0, 0.0, 3.0]] ... ) - >>> SC = tnx.SimplicialComplex.from_spharpy(mesh) + >>> SC = tnx.SimplicialComplex.from_spharapy(mesh) """ vertices = np.array(mesh.vertlist) SC = cls(mesh.trilist) @@ -1612,7 +1612,7 @@ def to_trimesh(self, vertex_position_name: str = "position"): ) def to_spharapy(self, vertex_position_name: str = "position"): - """Convert to sharapy. + """Convert to spharapy. Parameters ---------- @@ -1635,7 +1635,7 @@ def to_spharapy(self, vertex_position_name: str = "position"): >>> import spharapy.spharabasis as sb >>> import spharapy.datasets as sd >>> mesh = tm.TriMesh([[0, 1, 2]], [[0, 0, 0], [0, 0, 1], [0, 1, 0]]) - >>> SC = tnx.SimplicialComplex.from_spharpy(mesh) + >>> SC = tnx.SimplicialComplex.from_spharapy(mesh) >>> mesh2 = SC.to_spharapy() >>> mesh2.vertlist == mesh.vertlist >>> mesh2.trilist == mesh.trilist From 7a75a4649ca60e30e1e2bfda97f4daa8ef196e18 Mon Sep 17 00:00:00 2001 From: Florian Frantzen Date: Fri, 3 Jan 2025 11:21:33 +0100 Subject: [PATCH 2/2] Keep old from_spharpy as deprecated function --- test/classes/test_simplicial_complex.py | 20 ++++++++++++++++++++ toponetx/classes/simplicial_complex.py | 17 +++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/test/classes/test_simplicial_complex.py b/test/classes/test_simplicial_complex.py index d1ec01f5..0d102bab 100644 --- a/test/classes/test_simplicial_complex.py +++ b/test/classes/test_simplicial_complex.py @@ -1112,6 +1112,26 @@ def test_from_spharapy(self): assert [1] in simplices assert [2] in simplices + @pytest.mark.skipif( + tm is None, reason="Optional dependency 'spharapy' not installed." + ) + def test_from_spharpy(self): + """Test the deprecated from_spharpy method of SimplicialComplex (support for spharapy trimesh).""" + mesh = tm.TriMesh( + [[0, 1, 2]], [[1.0, 0.0, 0.0], [0.0, 2.0, 0.0], [0.0, 0.0, 3.0]] + ) + with pytest.deprecated_call(): + SC = SimplicialComplex.from_spharpy(mesh) + simplices = SC.simplices + assert len(simplices) == 7 + assert [0, 1, 2] in simplices + assert [0, 1] in simplices + assert [0, 2] in simplices + assert [1, 2] in simplices + assert [0] in simplices + assert [1] in simplices + assert [2] in simplices + def test_graph_skeleton(self): """Test the graph_skeleton method of SimplicialComplex.""" SC = SimplicialComplex( diff --git a/toponetx/classes/simplicial_complex.py b/toponetx/classes/simplicial_complex.py index 3be9bd81..08e054b6 100644 --- a/toponetx/classes/simplicial_complex.py +++ b/toponetx/classes/simplicial_complex.py @@ -1440,6 +1440,23 @@ def from_spharapy(cls, mesh) -> Self: return SC + @classmethod + @deprecated("`SimplicialComplex.from_spharpy` is deprecated and will be removed in the future, use `SimplicialComplex.from_spharapy` instead.") + def from_spharpy(cls, mesh) -> Self: + """Import from sharpy. + + Parameters + ---------- + mesh : spharapy.trimesh.TriMesh + The input spharapy object. + + Returns + ------- + SimplicialComplex + The resulting SimplicialComplex. + """ + return cls.from_spharapy(mesh) + def to_hasse_graph(self) -> nx.DiGraph: """Create the hasse graph corresponding to this simplicial complex.