catch empty sets before fit #265

Merged
dominik merged 1 commits from 261-fit-empty-data into master 2024-04-04 17:26:53 +00:00
2 changed files with 5 additions and 2 deletions

View File

@ -543,7 +543,7 @@ class UpperManagement(QtCore.QObject):
else:
d = fit_d.Data(_x[inside], _y[inside], we=we[inside], idx=set_id, complex_type=data_complex)
except Exception as e:
raise Exception(f'Setting data failed for {set_id}')
raise Exception(f'Setting data failed for {data_i.name}') from e
d.set_model(m)
try:
@ -559,7 +559,7 @@ class UpperManagement(QtCore.QObject):
return True
except Exception as e:
logger.error('Fit preparation failed', *e.args)
logger.error(f'Fit preparation failed with error: {e.args}')
QtWidgets.QMessageBox.warning(QtWidgets.QWidget(),
'Fit prep failed',
f'Fit preparation failed:\n'

View File

@ -10,6 +10,9 @@ class Data:
def __init__(self, x, y, we=None, idx=None, complex_type: int = 0):
self.x = np.asarray(x)
self.y = np.asarray(y)
if self.x.size == 0 or self.y.size == 0:
raise ValueError("Data is empty")
if self.y.shape[0] != self.x.shape[0]:
raise ValueError(f'x and y have different lengths {self.x.shape[0]} and {self.y.shape[0]}')