From 7c7106187700d3e719819901c82fc9dceb7cc4cf Mon Sep 17 00:00:00 2001 From: Dominik Demuth Date: Wed, 29 Nov 2023 08:11:14 +0000 Subject: [PATCH] deal with missing weight key get_state and set_state; partly fixes #158 --- src/nmreval/fit/result.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/nmreval/fit/result.py b/src/nmreval/fit/result.py index 37d513f..27b293b 100644 --- a/src/nmreval/fit/result.py +++ b/src/nmreval/fit/result.py @@ -393,8 +393,7 @@ class FitResult(Points): def get_state(self): state = super().get_state() - for attr in ['idx', 'fun_kwargs', 'nobs', 'nvar', - 'islog', 'iscomplex', 'x_data', 'y_data']: + for attr in ['idx', 'fun_kwargs', 'nobs', 'nvar', 'we', 'islog', 'iscomplex', 'x_data', 'y_data']: state[attr] = getattr(self, attr) state['name'] = self._model_name @@ -412,6 +411,8 @@ class FitResult(Points): @staticmethod def set_state(state, **kwargs): state['params'] = {k: Parameter.set_state(v) for k, v in state.pop('params').items()} + if 'we' not in state: + state['we'] = '?' data = FitResult(**state) return data @@ -440,6 +441,9 @@ class FitResult(Points): return new_fit def sub(self, x_values): + if self.func is None: + raise ValueError('no fit function available to calculate new y values') + part_functions = [] actual_mode = -1 if 'complex_mode' in self.fun_kwargs: