Skip to content

Commit

Permalink
Fix reading empty Pandas DataFrame error
Browse files Browse the repository at this point in the history
  • Loading branch information
mpvanderschelling committed Jun 26, 2024
1 parent ca4606c commit f63e1d3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
4 changes: 4 additions & 0 deletions src/f3dasm/_src/experimentdata/_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@
class TemporaryFilesNotCleared(Exception):
pass


class ReadingEmptyPandasDataFrameError(Exception):
pass

# Storing methods
# =============================================================================

Expand Down
28 changes: 17 additions & 11 deletions src/f3dasm/_src/experimentdata/experimentdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
# =========================================================================
Expand Down

0 comments on commit f63e1d3

Please sign in to comment.