Skip to content

Commit d689959

Browse files
authored
fix: Check if configs appears multiple times when creating an obs (#216)
1 parent eb83ff2 commit d689959

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

pyerrors/obs.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,9 @@ def __init__(self, samples, names, idl=None, **kwargs):
104104
elif isinstance(idx, (list, np.ndarray)):
105105
dc = np.unique(np.diff(idx))
106106
if np.any(dc < 0):
107-
raise ValueError("Unsorted idx for idl[%s]" % (name))
107+
raise ValueError("Unsorted idx for idl[%s] at position %s" % (name, ' '.join(['%s' % (pos + 1) for pos in np.where(np.diff(idx) < 0)[0]])))
108+
elif np.any(dc == 0):
109+
raise ValueError("Duplicate entries in idx for idl[%s] at position %s" % (name, ' '.join(['%s' % (pos + 1) for pos in np.where(np.diff(idx) == 0)[0]])))
108110
if len(dc) == 1:
109111
self.idl[name] = range(idx[0], idx[-1] + dc[0], dc[0])
110112
else:

tests/obs_test.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ def test_Obs_exceptions():
4040
pe.Obs([np.random.rand(4)], ['name'])
4141
with pytest.raises(ValueError):
4242
pe.Obs([np.random.rand(5)], ['1'], idl=[[5, 3, 2 ,4 ,1]])
43+
with pytest.raises(ValueError):
44+
pe.Obs([np.random.rand(5)], ['1'], idl=[[1, 2, 3, 3, 5]])
45+
with pytest.raises(ValueError):
46+
pe.Obs([np.random.rand(5)], ['1'], idl=[[1, 1, 3, 1, 5]])
4347
with pytest.raises(TypeError):
4448
pe.Obs([np.random.rand(5)], ['1'], idl=['t'])
4549
with pytest.raises(ValueError):

0 commit comments

Comments
 (0)