From 4708ee9861b3fbbd3599055021aabdc447a11144 Mon Sep 17 00:00:00 2001 From: leufen1 <l.leufen@fz-juelich.de> Date: Fri, 22 Jul 2022 12:24:13 +0200 Subject: [PATCH] only stop time if time attr is still present --- mlair/run_modules/run_environment.py | 27 ++++++++++---------- test/test_run_modules/test_pre_processing.py | 23 ----------------- 2 files changed, 14 insertions(+), 36 deletions(-) diff --git a/mlair/run_modules/run_environment.py b/mlair/run_modules/run_environment.py index 191ee30f..2bc81750 100644 --- a/mlair/run_modules/run_environment.py +++ b/mlair/run_modules/run_environment.py @@ -113,21 +113,22 @@ class RunEnvironment(object): not as inheritance from this class, log file is copied and data store is cleared. """ if not self.del_by_exit: - self.time.stop() - try: - logging.info(f"{self._name} finished after {self.time}") - except NameError: - pass - self.del_by_exit = True - # copy log file and clear data store only if called as base class and not as super class - if self.__class__.__name__ == "RunEnvironment": + if hasattr(self, "time"): + self.time.stop() try: - self.__plot_tracking() - self.__save_tracking() - self.__move_log_file() - except (FileNotFoundError, NameError): + logging.info(f"{self._name} finished after {self.time}") + except NameError: pass - self.data_store.clear_data_store() + self.del_by_exit = True + # copy log file and clear data store only if called as base class and not as super class + if self.__class__.__name__ == "RunEnvironment": + try: + self.__plot_tracking() + self.__save_tracking() + self.__move_log_file() + except (FileNotFoundError, NameError): + pass + self.data_store.clear_data_store() def __enter__(self): """Enter run environment.""" diff --git a/test/test_run_modules/test_pre_processing.py b/test/test_run_modules/test_pre_processing.py index 743900bb..2bbdb302 100644 --- a/test/test_run_modules/test_pre_processing.py +++ b/test/test_run_modules/test_pre_processing.py @@ -9,8 +9,6 @@ from mlair.helpers import PyTestRegex from mlair.run_modules.experiment_setup import ExperimentSetup from mlair.run_modules.pre_processing import PreProcessing from mlair.run_modules.run_environment import RunEnvironment -import pandas as pd -import numpy as np import multiprocessing @@ -146,24 +144,3 @@ class TestPreProcessing: class data_preparation_no_trans: pass assert pre.transformation(data_preparation_no_trans, stations) is None - - # @pytest.fixture - # def dummy_df(self): - # data_dict = {'station_name': {'DEBW013': 'Stuttgart Bad Cannstatt', 'DEBW076': 'Baden-Baden', - # 'DEBW087': 'Schwäbische_Alb', 'DEBW107': 'Tübingen', - # 'DEBY081': 'Garmisch-Partenkirchen/Kreuzeckbahnstraße', '# Stations': np.nan, - # '# Samples': np.nan}, - # 'station_lon': {'DEBW013': 9.2297, 'DEBW076': 8.2202, 'DEBW087': 9.2076, 'DEBW107': 9.0512, - # 'DEBY081': 11.0631, '# Stations': np.nan, '# Samples': np.nan}, - # 'station_lat': {'DEBW013': 48.8088, 'DEBW076': 48.7731, 'DEBW087': 48.3458, 'DEBW107': 48.5077, - # 'DEBY081': 47.4764, '# Stations': np.nan, '# Samples': np.nan}, - # 'station_alt': {'DEBW013': 235.0, 'DEBW076': 148.0, 'DEBW087': 798.0, 'DEBW107': 325.0, - # 'DEBY081': 735.0, '# Stations': np.nan, '# Samples': np.nan}, - # 'train': {'DEBW013': 1413, 'DEBW076': 3002, 'DEBW087': 3016, 'DEBW107': 1782, 'DEBY081': 2837, - # '# Stations': 6, '# Samples': 12050}, - # 'val': {'DEBW013': 698, 'DEBW076': 715, 'DEBW087': 700, 'DEBW107': 701, 'DEBY081': 456, - # '# Stations': 6, '# Samples': 3270}, - # 'test': {'DEBW013': 1066, 'DEBW076': 696, 'DEBW087': 1080, 'DEBW107': 1080, 'DEBY081': 700, - # '# Stations': 6, '# Samples': 4622}} - # df = pd.DataFrame.from_dict(data_dict) - # return df -- GitLab