Skip to content

Commit

Permalink
Experiment.summary() should show all columns when summary_columns=None
Browse files Browse the repository at this point in the history
  • Loading branch information
wookayin committed Nov 10, 2023
1 parent 675aa5c commit 3e9ccec
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
14 changes: 10 additions & 4 deletions expt/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -886,18 +886,24 @@ def _df(self) -> pd.DataFrame:
},
})

if self._summary_columns:
# TODO: h.summary is expensive and slow, cache it
def _append_summary(summary_columns):
nonlocal df
df = pd.concat([
df,
pd.DataFrame({
k: [
h.summary(columns=self._summary_columns).loc[0, k]
# TODO: h.summary is expensive and slow, cache it
h.summary(columns=summary_columns).loc[0, k]
for h in self._hypotheses.values()
] for k in self._summary_columns
] for k in summary_columns
}),
], axis=1) # yapf: disable

if self._summary_columns is not None:
_append_summary(summary_columns=self._summary_columns)
else:
_append_summary(summary_columns=self.columns)

# Need to sort index w.r.t the multi-index level hierarchy, because
# the order of hypotheses being added is not guaranteed
df = df.set_index([*self._config_keys, 'name']).sort_index()
Expand Down
6 changes: 6 additions & 0 deletions expt/data_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,9 @@ def test_create_simple(self):
assert len(ex.hypotheses) == 1
assert ex.name == "one_hypo"

assert ex._summary_columns is None
assert list(ex._df.columns) == ["hypothesis", "x", "y", "z"]

def test_create_from_dataframe_run(self, runs_gridsearch: RunList):
"""Tests Experiment.from_dataframe with the minimal defaults."""

Expand Down Expand Up @@ -601,6 +604,9 @@ def test_create_from_dataframe_run_multicolumns(self,
assert list(ex._df.index.names) == ['algo', 'name'] # Note the order
# yapf: enable

# All other columns than by = "algo"
assert ex._summary_columns == ("env_id", "seed")

# by: not exists?
with pytest.raises(KeyError): # TODO: Improve exception
ex = Experiment.from_dataframe(df, by="unknown", name="Exp.foobar")
Expand Down

0 comments on commit 3e9ccec

Please sign in to comment.