Skip to content

Commit b81d590

Browse files
committed
Fix empty table if not all results are available
1 parent 82662c9 commit b81d590

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

src/cloudai/report_generator/comparison_report.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,12 +143,13 @@ def create_table(
143143
no_wrap=False,
144144
)
145145

146-
for row_idx in range(len(dfs[0][info_columns[0]])):
146+
df_with_max_rows = max(dfs, key=len)
147+
for row_idx in range(len(df_with_max_rows[info_columns[0]])):
147148
data = []
148149
for df in dfs:
149-
data.extend([str(df[col].get(row_idx)) for col in data_columns])
150+
data.extend([str(df[col].get(row_idx, "n/a")) for col in data_columns])
150151

151-
table.add_row(*[str(dfs[0][col][row_idx]) for col in info_columns], *data)
152+
table.add_row(*[str(df_with_max_rows[col][row_idx]) for col in info_columns], *data)
152153

153154
return table
154155

tests/report_generation_strategy/test_comparison_report.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ def test_one_data_point_is_empty(self, cmp_report: MyComparisonReport, nccl_tr:
101101
],
102102
),
103103
[
104-
pd.DataFrame({"size": [1, 2, 4], "value": [10, 20, 40]}),
105104
pd.DataFrame({"size": [], "value": []}),
105+
pd.DataFrame({"size": [1, 2, 4], "value": [10, 20, 40]}),
106106
],
107107
"title",
108108
["size"],
@@ -112,8 +112,8 @@ def test_one_data_point_is_empty(self, cmp_report: MyComparisonReport, nccl_tr:
112112
assert len(table.columns) == 3
113113
assert len(table.rows) == 3
114114
assert list(table.columns[0].cells) == ["1", "2", "4"]
115-
assert list(table.columns[1].cells) == ["10", "20", "40"]
116-
assert list(table.columns[2].cells) == ["None", "None", "None"]
115+
assert list(table.columns[1].cells) == ["n/a", "n/a", "n/a"]
116+
assert list(table.columns[2].cells) == ["10", "20", "40"]
117117

118118

119119
def test_create_charts(cmp_report: MyComparisonReport, nccl_tr: TestRun) -> None:

0 commit comments

Comments
 (0)