Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix from_spharapy naming in SimplicialComplex #403

Merged
merged 2 commits into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions test/classes/test_simplicial_complex.py
Original file line number Diff line number Diff line change
Expand Up @@ -1093,15 +1093,35 @@ def test_normalized_laplacian_matrix(self):
),
)

@pytest.mark.skipif(
tm is None, reason="Optional dependency 'spharapy' not installed."
)
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_spharapy(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

@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)."""
"""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]]
)
SC = SimplicialComplex.from_spharpy(mesh)
with pytest.deprecated_call():
SC = SimplicialComplex.from_spharpy(mesh)
simplices = SC.simplices
assert len(simplices) == 7
assert [0, 1, 2] in simplices
Expand Down
25 changes: 21 additions & 4 deletions toponetx/classes/simplicial_complex.py
Original file line number Diff line number Diff line change
Expand Up @@ -1401,7 +1401,7 @@
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
Expand All @@ -1423,7 +1423,7 @@
... [[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)
Expand All @@ -1440,6 +1440,23 @@

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.

Expand Down Expand Up @@ -1612,7 +1629,7 @@
)

def to_spharapy(self, vertex_position_name: str = "position"):
"""Convert to sharapy.
"""Convert to spharapy.

Parameters
----------
Expand All @@ -1635,7 +1652,7 @@
>>> 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)

Check warning on line 1655 in toponetx/classes/simplicial_complex.py

View check run for this annotation

Codecov / codecov/patch

toponetx/classes/simplicial_complex.py#L1655

Added line #L1655 was not covered by tests
>>> mesh2 = SC.to_spharapy()
>>> mesh2.vertlist == mesh.vertlist
>>> mesh2.trilist == mesh.trilist
Expand Down
Loading