Skip to content

Commit

Permalink
fix: Check if configs appears multiple times when creating an obs (#216)
Browse files Browse the repository at this point in the history
  • Loading branch information
s-kuberski authored Nov 10, 2023
1 parent eb83ff2 commit d689959
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
4 changes: 3 additions & 1 deletion pyerrors/obs.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ def __init__(self, samples, names, idl=None, **kwargs):
elif isinstance(idx, (list, np.ndarray)):
dc = np.unique(np.diff(idx))
if np.any(dc < 0):
raise ValueError("Unsorted idx for idl[%s]" % (name))
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]])))
elif np.any(dc == 0):
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]])))
if len(dc) == 1:
self.idl[name] = range(idx[0], idx[-1] + dc[0], dc[0])
else:
Expand Down
4 changes: 4 additions & 0 deletions tests/obs_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ def test_Obs_exceptions():
pe.Obs([np.random.rand(4)], ['name'])
with pytest.raises(ValueError):
pe.Obs([np.random.rand(5)], ['1'], idl=[[5, 3, 2 ,4 ,1]])
with pytest.raises(ValueError):
pe.Obs([np.random.rand(5)], ['1'], idl=[[1, 2, 3, 3, 5]])
with pytest.raises(ValueError):
pe.Obs([np.random.rand(5)], ['1'], idl=[[1, 1, 3, 1, 5]])
with pytest.raises(TypeError):
pe.Obs([np.random.rand(5)], ['1'], idl=['t'])
with pytest.raises(ValueError):
Expand Down

0 comments on commit d689959

Please sign in to comment.