Skip to content

Commit 01cd6a5

Browse files
committed
Add error to approx class for empty list and pairs
1 parent 27c291d commit 01cd6a5

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

persim/landscapes/approximate.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ def __init__(
130130
) -> None:
131131

132132
super().__init__(dgms=dgms, hom_deg=hom_deg)
133+
if not dgms and values.size == 0:
134+
raise ValueError("dgms and values cannot both be emtpy")
133135
if dgms: # diagrams are passed
134136
self.dgms = dgms[self.hom_deg]
135137
# remove infity values
@@ -142,9 +144,11 @@ def __init__(
142144
elif values.size > 0: # values passed, diagrams weren't
143145
self.dgms = dgms
144146
if start is None:
145-
raise ValueError("start parameter must be passed if values are passed.")
147+
raise ValueError("start parameter must be passed if values are passed")
146148
if stop is None:
147-
raise ValueError("stop parameter must be passed if values are passed.")
149+
raise ValueError("stop parameter must be passed if values are passed")
150+
if start > stop:
151+
raise ValueError("start must be less than or equal to stop")
148152
self.start = start
149153
self.stop = stop
150154
self.values = values

persim/landscapes/exact.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,10 @@ def __getitem__(self, key: slice) -> list:
240240
list
241241
The critical pairs of the landscape function corresponding
242242
to depths given by key
243+
244+
Note
245+
----
246+
If the slice is beyond `self.max_depth` an IndexError is raised.
243247
"""
244248
self.compute_landscape()
245249
return self.critical_pairs[key]

0 commit comments

Comments
 (0)