dustalov commited on
Commit
832c761
1 Parent(s): cc521be

Fix typing and linting

Browse files
Files changed (2) hide show
  1. app.py +17 -11
  2. ruff.toml +0 -1
app.py CHANGED
@@ -41,32 +41,38 @@ def visualize(df_pairwise: pd.DataFrame) -> Figure:
41
  return fig
42
 
43
 
44
- def counting(xs: list[str], ys: list[str], ws: list[Winner]) -> tuple["pd.Series[str]", "pd.Index[str]"]:
 
45
  result = evalica.counting(xs, ys, ws)
46
  return result.scores, result.index
47
 
48
 
49
- def bradley_terry(xs: list[str], ys: list[str], ws: list[Winner]) -> tuple["pd.Series[str]", "pd.Index[str]"]:
 
50
  result = evalica.bradley_terry(xs, ys, ws, tolerance=TOLERANCE, limit=LIMIT)
51
  return result.scores, result.index
52
 
53
 
54
- def elo(xs: list[str], ys: list[str], ws: list[Winner]) -> tuple["pd.Series[str]", "pd.Index[str]"]:
 
55
  result = evalica.elo(xs, ys, ws)
56
  return result.scores, result.index
57
 
58
 
59
- def eigen(xs: list[str], ys: list[str], ws: list[Winner]) -> tuple["pd.Series[str]", "pd.Index[str]"]:
 
60
  result = evalica.eigen(xs, ys, ws, tolerance=TOLERANCE, limit=LIMIT)
61
  return result.scores, result.index
62
 
63
 
64
- def pagerank(xs: list[str], ys: list[str], ws: list[Winner]) -> tuple["pd.Series[str]", "pd.Index[str]"]:
 
65
  result = evalica.pagerank(xs, ys, ws, tolerance=TOLERANCE, limit=LIMIT)
66
  return result.scores, result.index
67
 
68
 
69
- def newman(xs: list[str], ys: list[str], ws: list[Winner]) -> tuple["pd.Series[str]", "pd.Index[str]"]:
 
70
  result = evalica.newman(xs, ys, ws, tolerance=TOLERANCE, limit=LIMIT)
71
  return result.scores, result.index
72
 
@@ -115,12 +121,12 @@ def handler(
115
 
116
  df_pairs = df_pairs[["left", "right", "winner"]]
117
 
118
- df_pairs.dropna(axis=0, inplace=True)
119
 
120
  if filtered:
121
  largest = largest_strongly_connected_component(df_pairs)
122
 
123
- df_pairs.drop(df_pairs[~(df_pairs["left"].isin(largest) & df_pairs["right"].isin(largest))].index, inplace=True)
124
 
125
  xs, ys = df_pairs["left"], df_pairs["right"]
126
  ws = df_pairs["winner"].map({"left": Winner.X, "right": Winner.Y, "tie": Winner.Draw})
@@ -138,9 +144,9 @@ def handler(
138
 
139
  df_result["rank"] = df_result["score"].rank(na_option="bottom", ascending=False).astype(int)
140
 
141
- df_result.fillna(-np.inf, inplace=True)
142
- df_result.sort_values(by=["rank", "score"], ascending=[True, False], inplace=True)
143
- df_result.reset_index(inplace=True)
144
 
145
  if truncated:
146
  df_result = pd.concat((df_result.head(5), df_result.tail(5)), copy=False)
 
41
  return fig
42
 
43
 
44
+ def counting(xs: "pd.Series[str]", ys: "pd.Series[str]",
45
+ ws: "pd.Series[Winner]") -> tuple["pd.Series[str]", "pd.Index[str]"]: # type: ignore[type-var]
46
  result = evalica.counting(xs, ys, ws)
47
  return result.scores, result.index
48
 
49
 
50
+ def bradley_terry(xs: "pd.Series[str]", ys: "pd.Series[str]",
51
+ ws: "pd.Series[Winner]") -> tuple["pd.Series[str]", "pd.Index[str]"]: # type: ignore[type-var]
52
  result = evalica.bradley_terry(xs, ys, ws, tolerance=TOLERANCE, limit=LIMIT)
53
  return result.scores, result.index
54
 
55
 
56
+ def elo(xs: "pd.Series[str]", ys: "pd.Series[str]",
57
+ ws: "pd.Series[Winner]") -> tuple["pd.Series[str]", "pd.Index[str]"]: # type: ignore[type-var]
58
  result = evalica.elo(xs, ys, ws)
59
  return result.scores, result.index
60
 
61
 
62
+ def eigen(xs: "pd.Series[str]", ys: "pd.Series[str]",
63
+ ws: "pd.Series[Winner]") -> tuple["pd.Series[str]", "pd.Index[str]"]: # type: ignore[type-var]
64
  result = evalica.eigen(xs, ys, ws, tolerance=TOLERANCE, limit=LIMIT)
65
  return result.scores, result.index
66
 
67
 
68
+ def pagerank(xs: "pd.Series[str]", ys: "pd.Series[str]",
69
+ ws: "pd.Series[Winner]") -> tuple["pd.Series[str]", "pd.Index[str]"]: # type: ignore[type-var]
70
  result = evalica.pagerank(xs, ys, ws, tolerance=TOLERANCE, limit=LIMIT)
71
  return result.scores, result.index
72
 
73
 
74
+ def newman(xs: "pd.Series[str]", ys: "pd.Series[str]",
75
+ ws: "pd.Series[Winner]") -> tuple["pd.Series[str]", "pd.Index[str]"]: # type: ignore[type-var]
76
  result = evalica.newman(xs, ys, ws, tolerance=TOLERANCE, limit=LIMIT)
77
  return result.scores, result.index
78
 
 
121
 
122
  df_pairs = df_pairs[["left", "right", "winner"]]
123
 
124
+ df_pairs = df_pairs.dropna(axis=0)
125
 
126
  if filtered:
127
  largest = largest_strongly_connected_component(df_pairs)
128
 
129
+ df_pairs = df_pairs.drop(df_pairs[~(df_pairs["left"].isin(largest) & df_pairs["right"].isin(largest))].index)
130
 
131
  xs, ys = df_pairs["left"], df_pairs["right"]
132
  ws = df_pairs["winner"].map({"left": Winner.X, "right": Winner.Y, "tie": Winner.Draw})
 
144
 
145
  df_result["rank"] = df_result["score"].rank(na_option="bottom", ascending=False).astype(int)
146
 
147
+ df_result = df_result.fillna(-np.inf)
148
+ df_result = df_result.sort_values(by=["rank", "score"], ascending=[True, False])
149
+ df_result = df_result.reset_index()
150
 
151
  if truncated:
152
  df_result = pd.concat((df_result.head(5), df_result.tail(5)), copy=False)
ruff.toml CHANGED
@@ -9,6 +9,5 @@ ignore = [
9
  "EM102", # f-string-in-exception
10
  "FBT001", # boolean-type-hint-positional-argument
11
  "N806", # non-lowercase-variable-in-function
12
- "PD002", # pandas-use-of-inplace-argument
13
  "TRY003", # raise-vanilla-args
14
  ]
 
9
  "EM102", # f-string-in-exception
10
  "FBT001", # boolean-type-hint-positional-argument
11
  "N806", # non-lowercase-variable-in-function
 
12
  "TRY003", # raise-vanilla-args
13
  ]