Skip to content

Commit 0152cb6

Browse files
motuspre-commit-ci[bot]bpkroth
authored
Fail a trial if it produces empty csv file (#1006)
# Pull Request ## Title Fail a trial if it produces empty csv file. A follow-up to #998 ______________________________________________________________________ ## Description * Fail a trial if it produces empty csv file. * Add unit test to check for the condition. * Small fix in `split_cmdline()` function to allow empty token strings (occurs in the new unit test) ______________________________________________________________________ ## Type of Change - 🛠️ Bug fix - 🧪 Tests ______________________________________________________________________ ## Testing Run unit tests as usual --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Brian Kroth <bpkroth@users.noreply.github.com>
1 parent 5149a41 commit 0152cb6

3 files changed

Lines changed: 38 additions & 11 deletions

File tree

mlos_bench/mlos_bench/environments/local/local_env.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -195,19 +195,23 @@ def run(self) -> tuple[Status, datetime, dict[str, TunableValue] | None]:
195195
_LOG.debug("Not reading the data at: %s", self)
196196
return (Status.SUCCEEDED, timestamp, stdout_data)
197197

198-
data = self._normalize_columns(
199-
pandas.read_csv(
200-
self._config_loader_service.resolve_path(
201-
self._read_results_file,
202-
extra_paths=[self._temp_dir],
203-
),
204-
index_col=False,
198+
try:
199+
data = self._normalize_columns(
200+
pandas.read_csv(
201+
self._config_loader_service.resolve_path(
202+
self._read_results_file,
203+
extra_paths=[self._temp_dir],
204+
),
205+
index_col=False,
206+
)
205207
)
206-
)
208+
except pandas.errors.EmptyDataError:
209+
_LOG.warning("Empty metrics file - fail the run")
210+
return (Status.FAILED, timestamp, None)
207211

208212
_LOG.debug("Read data:\n%s", data)
209213
if len(data) == 0:
210-
_LOG.warning("Empty metrics file - fail the run")
214+
_LOG.warning("No data in the metrics file - fail the run")
211215
return (Status.FAILED, timestamp, None)
212216
elif list(data.columns) == ["metric", "value"]:
213217
_LOG.info(

mlos_bench/mlos_bench/services/local/local_exec.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def split_cmdline(cmdline: str) -> Iterable[list[str]]:
4646
cmdline_tokens.whitespace_split = True
4747
subcmd = []
4848
for token in cmdline_tokens:
49-
if token[0] not in cmdline_tokens.punctuation_chars:
49+
if token[:1] not in cmdline_tokens.punctuation_chars:
5050
subcmd.append(token)
5151
else:
5252
# Separator encountered. Yield any non-empty previous subcmd we accumulated.

mlos_bench/mlos_bench/tests/environments/local/local_env_test.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,31 @@ def test_local_env_wide(tunable_groups: TunableGroups) -> None:
104104
)
105105

106106

107+
def test_local_env_results_null_file(tunable_groups: TunableGroups) -> None:
108+
"""When the results file is of zero length, do not crash but mark the trial
109+
FAILED.
110+
"""
111+
local_env = create_local_env(
112+
tunable_groups,
113+
{
114+
"run": [
115+
"echo '' > output.csv",
116+
],
117+
"read_results_file": "output.csv",
118+
},
119+
)
120+
121+
check_env_success(
122+
local_env,
123+
tunable_groups,
124+
expected_status_run={Status.FAILED},
125+
expected_results=None,
126+
expected_telemetry=[],
127+
)
128+
129+
107130
def test_local_env_results_empty_file(tunable_groups: TunableGroups) -> None:
108-
"""When the results file is empty, do not crash but mark the trial FAILED."""
131+
"""When the results file has no data, do not crash but mark the trial FAILED."""
109132
local_env = create_local_env(
110133
tunable_groups,
111134
{

0 commit comments

Comments
 (0)