diff --git a/pyerrors/fits.py b/pyerrors/fits.py index d98f7aa0..8feb81fa 100644 --- a/pyerrors/fits.py +++ b/pyerrors/fits.py @@ -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=""): diff --git a/tests/fits_test.py b/tests/fits_test.py index 1af0e56e..92fffad5 100644 --- a/tests/fits_test.py +++ b/tests/fits_test.py @@ -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})