chore: Exception in least_squares specified.

This commit is contained in:
Fabian Joswig 2023-03-08 16:45:29 +00:00
parent e6051d7ba0
commit 80f4eef912
No known key found for this signature in database
2 changed files with 7 additions and 7 deletions

View file

@ -192,10 +192,10 @@ def least_squares(x, y, func, priors=None, silent=False, **kwargs):
key_ls = sorted(list(xd.keys()))
if sorted(list(yd.keys())) != key_ls:
raise Exception('x and y dictionaries do not contain the same keys.')
raise ValueError('x and y dictionaries do not contain the same keys.')
if sorted(list(funcd.keys())) != key_ls:
raise Exception('x and func dictionaries do not contain the same keys.')
raise ValueError('x and func dictionaries do not contain the same keys.')
x_all = np.concatenate([np.array(xd[key]) for key in key_ls])
y_all = np.concatenate([np.array(yd[key]) for key in key_ls])
@ -215,7 +215,7 @@ def least_squares(x, y, func, priors=None, silent=False, **kwargs):
if not callable(funcd[key]):
raise TypeError('func (key=' + key + ') is not a function.')
if np.asarray(xd[key]).shape[-1] != len(yd[key]):
raise Exception('x and y input (key=' + key + ') do not have the same length')
raise ValueError('x and y input (key=' + key + ') do not have the same length')
for i in range(100):
try:
funcd[key](np.arange(i), x_all.T[0])
@ -680,7 +680,7 @@ def fit_lin(x, y, **kwargs):
out = least_squares(x, y, f, **kwargs)
return out.fit_parameters
else:
raise Exception('Unsupported types for x')
raise TypeError('Unsupported types for x')
def qqplot(x, o_y, func, p, title=""):

View file

@ -713,15 +713,15 @@ def test_combined_fit_invalid_fit_functions():
def test_combined_fit_invalid_input():
xvals =[]
yvals =[]
xvals = []
yvals = []
err = 0.1
def func_valid(a,x):
return a[0] + a[1] * x
for x in range(1, 8, 2):
xvals.append(x)
yvals.append(pe.pseudo_Obs(x + np.random.normal(0.0, err), err, 'test1') + pe.pseudo_Obs(0, err / 100, 'test2', samples=87))
with pytest.raises(Exception):
with pytest.raises(ValueError):
pe.least_squares({'a':xvals}, {'b':yvals}, {'a':func_valid})
with pytest.raises(Exception):
pe.least_squares({'a':xvals}, {'a':yvals}, {'a':func_valid})