def test__sort_leaderboard_no_rank(): rank = None metrics = METRICS score = {k: range(5) for k in metrics.keys()} score['pipeline'] = range(5) score = pd.DataFrame(score) expected_return = score.iloc[::-1].reset_index(drop=True) expected_return['rank'] = range(1, 6) returned = benchmark._sort_leaderboard(score, rank, metrics) assert len(returned.columns) == len(expected_return.columns) assert sorted(returned.columns) == sorted(expected_return.columns) pd.testing.assert_frame_equal(returned, expected_return[returned.columns])
def test__sort_leaderboard_rank_does_not_exist(): rank = 'does not exist' metrics = {'f1': METRICS['f1']} score = pd.DataFrame({ 'pipeline': range(5), 'f1': range(5), }) expected_return = pd.DataFrame({ 'pipeline': range(5)[::-1], 'rank': range(1, 6), 'f1': range(5)[::-1], }) returned = benchmark._sort_leaderboard(score, rank, metrics) pd.testing.assert_frame_equal(returned, expected_return)
def test__sort_leaderboard_rank(): rank = 'f1' metrics = METRICS score = pd.DataFrame({ 'pipeline': range(5), 'f1': range(5), }) expected_return = pd.DataFrame({ 'pipeline': range(5)[::-1], 'rank': range(1, 6), 'f1': range(5)[::-1], }) returned = benchmark._sort_leaderboard(score, rank, metrics) pd.testing.assert_frame_equal(returned, expected_return)