From f63e1d30443e7eb54458c5723a488a051213e500 Mon Sep 17 00:00:00 2001 From: Martin van der Schelling <61459087+mpvanderschelling@users.noreply.github.com> Date: Wed, 26 Jun 2024 14:16:12 +0200 Subject: [PATCH] Fix reading empty Pandas DataFrame error --- src/f3dasm/_src/experimentdata/_io.py | 4 +++ .../_src/experimentdata/experimentdata.py | 28 +++++++++++-------- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/f3dasm/_src/experimentdata/_io.py b/src/f3dasm/_src/experimentdata/_io.py index 385f495e..b4a0d92f 100644 --- a/src/f3dasm/_src/experimentdata/_io.py +++ b/src/f3dasm/_src/experimentdata/_io.py @@ -51,6 +51,10 @@ class TemporaryFilesNotCleared(Exception): pass + +class ReadingEmptyPandasDataFrameError(Exception): + pass + # Storing methods # ============================================================================= diff --git a/src/f3dasm/_src/experimentdata/experimentdata.py b/src/f3dasm/_src/experimentdata/experimentdata.py index 8deb2fff..f6d1ac49 100644 --- a/src/f3dasm/_src/experimentdata/experimentdata.py +++ b/src/f3dasm/_src/experimentdata/experimentdata.py @@ -38,8 +38,8 @@ from ._data import DataTypes, _Data, _data_factory from ._io import (DOMAIN_FILENAME, EXPERIMENTDATA_SUBFOLDER, INPUT_DATA_FILENAME, JOBS_FILENAME, LOCK_FILENAME, MAX_TRIES, - OUTPUT_DATA_FILENAME, _project_dir_factory, - check_for_temporary_files) + OUTPUT_DATA_FILENAME, ReadingEmptyPandasDataFrameError, + _project_dir_factory, check_for_temporary_files) from ._jobqueue import NoOpenJobsError, Status, _jobs_factory from .experimentsample import ExperimentSample from .samplers import Sampler, SamplerNames, _sampler_factory @@ -398,15 +398,21 @@ def _from_file_attempt(cls: Type[ExperimentData], # check if there is any .tmp file in the subdirectory check_for_temporary_files(subdirectory) - try: - return cls(domain=subdirectory / DOMAIN_FILENAME, - input_data=subdirectory / INPUT_DATA_FILENAME, - output_data=subdirectory / OUTPUT_DATA_FILENAME, - jobs=subdirectory / JOBS_FILENAME, - project_dir=project_dir) - except FileNotFoundError: - raise FileNotFoundError( - f"Cannot find the files from {subdirectory}.") + for attempt in range(MAX_TRIES): + try: + return cls(domain=subdirectory / DOMAIN_FILENAME, + input_data=subdirectory / INPUT_DATA_FILENAME, + output_data=subdirectory / OUTPUT_DATA_FILENAME, + jobs=subdirectory / JOBS_FILENAME, + project_dir=project_dir) + except FileNotFoundError: + raise FileNotFoundError( + f"Cannot find the files from {subdirectory}.") + except pd.errors.EmptyDataError: + sleep(1) + continue + + raise ReadingEmptyPandasDataFrameError(f"Reading empty dataframes") # Selecting subsets # =========================================================================