Skip to content

Commit 6a30ac8

Browse files
authored
Merge pull request #403 from luisfpereira/fix-typo-spharapy
Fix `from_spharapy` naming in `SimplicialComplex`
2 parents f652c82 + 7a75a46 commit 6a30ac8

File tree

2 files changed

+43
-6
lines changed

2 files changed

+43
-6
lines changed

test/classes/test_simplicial_complex.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,15 +1073,35 @@ def test_normalized_laplacian_matrix(self):
10731073
),
10741074
)
10751075

1076+
@pytest.mark.skipif(
1077+
tm is None, reason="Optional dependency 'spharapy' not installed."
1078+
)
1079+
def test_from_spharapy(self):
1080+
"""Test the from_spharapy method of SimplicialComplex (support for spharapy trimesh)."""
1081+
mesh = tm.TriMesh(
1082+
[[0, 1, 2]], [[1.0, 0.0, 0.0], [0.0, 2.0, 0.0], [0.0, 0.0, 3.0]]
1083+
)
1084+
SC = SimplicialComplex.from_spharapy(mesh)
1085+
simplices = SC.simplices
1086+
assert len(simplices) == 7
1087+
assert [0, 1, 2] in simplices
1088+
assert [0, 1] in simplices
1089+
assert [0, 2] in simplices
1090+
assert [1, 2] in simplices
1091+
assert [0] in simplices
1092+
assert [1] in simplices
1093+
assert [2] in simplices
1094+
10761095
@pytest.mark.skipif(
10771096
tm is None, reason="Optional dependency 'spharapy' not installed."
10781097
)
10791098
def test_from_spharpy(self):
1080-
"""Test the from_spharpy method of SimplicialComplex (support for spharpy trimesh)."""
1099+
"""Test the deprecated from_spharpy method of SimplicialComplex (support for spharapy trimesh)."""
10811100
mesh = tm.TriMesh(
10821101
[[0, 1, 2]], [[1.0, 0.0, 0.0], [0.0, 2.0, 0.0], [0.0, 0.0, 3.0]]
10831102
)
1084-
SC = SimplicialComplex.from_spharpy(mesh)
1103+
with pytest.deprecated_call():
1104+
SC = SimplicialComplex.from_spharpy(mesh)
10851105
simplices = SC.simplices
10861106
assert len(simplices) == 7
10871107
assert [0, 1, 2] in simplices

toponetx/classes/simplicial_complex.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1350,7 +1350,7 @@ def get_all_maximal_simplices(self) -> Generator[Simplex[ElementType], None, Non
13501350
yield simplex
13511351

13521352
@classmethod
1353-
def from_spharpy(cls, mesh) -> Self:
1353+
def from_spharapy(cls, mesh) -> Self:
13541354
"""Import from sharpy.
13551355
13561356
Parameters
@@ -1372,7 +1372,7 @@ def from_spharpy(cls, mesh) -> Self:
13721372
... [[0, 1, 2]], [[1.0, 0.0, 0.0], [0.0, 2.0, 0.0], [0.0, 0.0, 3.0]]
13731373
... )
13741374
1375-
>>> SC = tnx.SimplicialComplex.from_spharpy(mesh)
1375+
>>> SC = tnx.SimplicialComplex.from_spharapy(mesh)
13761376
"""
13771377
vertices = np.array(mesh.vertlist)
13781378
SC = cls(mesh.trilist)
@@ -1389,6 +1389,23 @@ def from_spharpy(cls, mesh) -> Self:
13891389

13901390
return SC
13911391

1392+
@classmethod
1393+
@deprecated("`SimplicialComplex.from_spharpy` is deprecated and will be removed in the future, use `SimplicialComplex.from_spharapy` instead.")
1394+
def from_spharpy(cls, mesh) -> Self:
1395+
"""Import from sharpy.
1396+
1397+
Parameters
1398+
----------
1399+
mesh : spharapy.trimesh.TriMesh
1400+
The input spharapy object.
1401+
1402+
Returns
1403+
-------
1404+
SimplicialComplex
1405+
The resulting SimplicialComplex.
1406+
"""
1407+
return cls.from_spharapy(mesh)
1408+
13921409
def to_hasse_graph(self) -> nx.DiGraph:
13931410
"""Create the hasse graph corresponding to this simplicial complex.
13941411
@@ -1560,7 +1577,7 @@ def to_trimesh(self, vertex_position_name: str = "position"):
15601577
return trimesh.Trimesh(faces=faces, vertices=vertices, process=False)
15611578

15621579
def to_spharapy(self, vertex_position_name: str = "position"):
1563-
"""Convert to sharapy.
1580+
"""Convert to spharapy.
15641581
15651582
Parameters
15661583
----------
@@ -1583,7 +1600,7 @@ def to_spharapy(self, vertex_position_name: str = "position"):
15831600
>>> import spharapy.spharabasis as sb
15841601
>>> import spharapy.datasets as sd
15851602
>>> mesh = tm.TriMesh([[0, 1, 2]], [[0, 0, 0], [0, 0, 1], [0, 1, 0]])
1586-
>>> SC = tnx.SimplicialComplex.from_spharpy(mesh)
1603+
>>> SC = tnx.SimplicialComplex.from_spharapy(mesh)
15871604
>>> mesh2 = SC.to_spharapy()
15881605
>>> mesh2.vertlist == mesh.vertlist
15891606
>>> mesh2.trilist == mesh.trilist

0 commit comments

Comments
 (0)