diff --git a/message_ix/macro.py b/message_ix/macro.py index 803a57834..18d22fd44 100644 --- a/message_ix/macro.py +++ b/message_ix/macro.py @@ -351,14 +351,20 @@ def _aconst(self): return self.data['aconst'] +def remove(s): + for key in MACRO_INIT['sets']: + if key in s.set_list(): + s.remove_set(key) + for key in MACRO_INIT['pars']: + if key in s.par_list(): + s.remove_par(key) + + def init(s): for key, values in MACRO_INIT['sets'].items(): s.init_set(key, values) for key, values in MACRO_INIT['pars'].items(): - try: - s.init_par(key, values['idx']) - except: # noqa: ignore=E722 - pass # already exists in the model, known for 'historical_gdp' + s.init_par(key, values['idx']) for key, values in MACRO_INIT['vars'].items(): if not s.has_var(key): try: diff --git a/tests/test_macro.py b/tests/test_macro.py index 059b7fb2f..8450cc4db 100644 --- a/tests/test_macro.py +++ b/tests/test_macro.py @@ -188,6 +188,7 @@ def test_init(test_mp): scen = scen.clone('foo', 'bar') scen.check_out() + macro.remove(scen) macro.init(scen) scen.commit('foo') scen.solve()