Spaces:
AIR-Bench
/
Running on CPU Upgrade

nan commited on
Commit
cbe1b0d
1 Parent(s): 2c23c13

fix: fix the bug in unselecting anonymous

Browse files
Files changed (2) hide show
  1. src/utils.py +3 -3
  2. tests/test_utils.py +22 -2
src/utils.py CHANGED
@@ -113,10 +113,10 @@ def select_columns(
113
  selected_cols.append(c)
114
  # We use COLS to maintain sorting
115
  filtered_df = df[FIXED_COLS + selected_cols]
116
- filtered_df[COL_NAME_AVG] = filtered_df[selected_cols].apply(calculate_mean, axis=1).round(decimals=2)
117
- filtered_df.sort_values(by=[COL_NAME_AVG], ascending=False, inplace=True)
118
- filtered_df.reset_index(inplace=True, drop=True)
119
  if reset_ranking:
 
 
 
120
  filtered_df[COL_NAME_RANK] = filtered_df[COL_NAME_AVG].rank(ascending=False, method="min")
121
 
122
  return filtered_df
 
113
  selected_cols.append(c)
114
  # We use COLS to maintain sorting
115
  filtered_df = df[FIXED_COLS + selected_cols]
 
 
 
116
  if reset_ranking:
117
+ filtered_df[COL_NAME_AVG] = filtered_df[selected_cols].apply(calculate_mean, axis=1).round(decimals=2)
118
+ filtered_df.sort_values(by=[COL_NAME_AVG], ascending=False, inplace=True)
119
+ filtered_df.reset_index(inplace=True, drop=True)
120
  filtered_df[COL_NAME_RANK] = filtered_df[COL_NAME_AVG].rank(ascending=False, method="min")
121
 
122
  return filtered_df
tests/test_utils.py CHANGED
@@ -1,7 +1,8 @@
1
  import pandas as pd
2
  import pytest
3
 
4
- from src.utils import filter_models, search_table, filter_queries, select_columns, update_table_long_doc, get_iso_format_timestamp, get_default_cols
 
5
 
6
 
7
  @pytest.fixture
@@ -92,4 +93,23 @@ def test_get_default_cols():
92
  cols, types = get_default_cols("qa")
93
  for c, t in zip(cols, types):
94
  print(f"type({c}): {t}")
95
- assert len(frozenset(cols)) == len(cols)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import pandas as pd
2
  import pytest
3
 
4
+ from src.utils import filter_models, search_table, filter_queries, select_columns, update_table_long_doc, get_iso_format_timestamp, get_default_cols, update_table
5
+ from src.display.utils import COL_NAME_IS_ANONYMOUS, COL_NAME_REVISION, COL_NAME_TIMESTAMP, COL_NAME_RERANKING_MODEL, COL_NAME_RETRIEVAL_MODEL, COL_NAME_RANK, COL_NAME_AVG
6
 
7
 
8
  @pytest.fixture
 
93
  cols, types = get_default_cols("qa")
94
  for c, t in zip(cols, types):
95
  print(f"type({c}): {t}")
96
+ assert len(frozenset(cols)) == len(cols)
97
+
98
+
99
+ def test_update_table():
100
+ df = pd.DataFrame(
101
+ {
102
+ COL_NAME_IS_ANONYMOUS: [False, False, False],
103
+ COL_NAME_REVISION: ["a1", "a2", "a3"],
104
+ COL_NAME_TIMESTAMP: ["2024-05-12T12:24:02Z"] * 3,
105
+ COL_NAME_RERANKING_MODEL: ["NoReranker"] * 3,
106
+ COL_NAME_RETRIEVAL_MODEL: ["Foo"] * 3,
107
+ COL_NAME_RANK: [1, 2, 3],
108
+ COL_NAME_AVG: [0.1, 0.2, 0.3], # unsorted values
109
+ "wiki_en": [0.1, 0.2, 0.3]
110
+ }
111
+ )
112
+ results = update_table(df, "wiki", "en", ["NoReranker"], "", show_anonymous=False, reset_ranking=False, show_revision_and_timestamp=False)
113
+ # keep the RANK as the same regardless of the unsorted averages
114
+ assert results[COL_NAME_RANK].to_list() == [1, 2, 3]
115
+