Skip to content

Commit 32449e1

Browse files
Merge pull request #990 from christeefy/bug/evaluate-display-table-arg
fix(evaluate): `Evaluate` should not error when `display_table=True`
2 parents 012b07a + d1075af commit 32449e1

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

dspy/evaluate/evaluate.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -218,12 +218,12 @@ def wrapped_program(example_idx, example):
218218
result_df = result_df.rename(columns={"correct": metric_name})
219219

220220
if display_table:
221-
if isinstance(display_table, int):
222-
df_to_display = result_df.head(display_table).copy()
223-
truncated_rows = len(result_df) - display_table
224-
else:
221+
if isinstance(display_table, bool):
225222
df_to_display = result_df.copy()
226223
truncated_rows = 0
224+
else:
225+
df_to_display = result_df.head(display_table).copy()
226+
truncated_rows = len(result_df) - display_table
227227

228228
styled_df = configure_dataframe_display(df_to_display, metric_name)
229229

tests/evaluate/test_evaluate.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,17 @@ def test_evaluate_call_bad():
112112
assert score == 0.0
113113

114114

115-
def test_evaluate_display_table():
115+
@pytest.mark.parametrize(
116+
"display_table", [True, False, 1]
117+
)
118+
def test_evaluate_display_table(display_table):
116119
devset = [new_example("What is 1+1?", "2")]
120+
program = Predict("question -> answer")
117121
ev = Evaluate(
118122
devset=devset,
119123
metric=answer_exact_match,
120-
display_table=True,
124+
display_table=display_table,
121125
)
122-
assert ev.display_table == True
126+
assert ev.display_table == display_table
127+
128+
ev(program)

0 commit comments

Comments
 (0)