From 921c13cc90ffad7102e7271631591a12b58546c5 Mon Sep 17 00:00:00 2001 From: you-n-g Date: Sun, 13 Mar 2022 11:11:41 +0800 Subject: [PATCH] safe remove file and more friendly log (#967) * save remove file and more friendly log * fix pylint --- qlib/model/riskmodel/structured.py | 1 - qlib/workflow/recorder.py | 8 +++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/qlib/model/riskmodel/structured.py b/qlib/model/riskmodel/structured.py index d9a2ec130..eb0fec58f 100644 --- a/qlib/model/riskmodel/structured.py +++ b/qlib/model/riskmodel/structured.py @@ -2,7 +2,6 @@ # Licensed under the MIT License. import numpy as np -import pandas as pd from typing import Union from sklearn.decomposition import PCA, FactorAnalysis diff --git a/qlib/workflow/recorder.py b/qlib/workflow/recorder.py index 3d64e268e..67759e590 100644 --- a/qlib/workflow/recorder.py +++ b/qlib/workflow/recorder.py @@ -351,14 +351,16 @@ class MLflowRecorder(Recorder): path = self.client.download_artifacts(self.id, name) with Path(path).open("rb") as f: data = unpickler(f).load() + return data + except Exception as e: + logger.exception(f"Fail to load data '{name}'") + raise LoadObjectError(str(e)) from e + finally: ar = self.client._tracking_client._get_artifact_repo(self.id) if isinstance(ar, AzureBlobArtifactRepository): # for saving disk space # For safety, only remove redundant file for specific ArtifactRepository shutil.rmtree(Path(path).absolute().parent) - return data - except Exception as e: - raise LoadObjectError(str(e)) from e @AsyncCaller.async_dec(ac_attr="async_log") def log_params(self, **kwargs):