Skip to content

Commit 0c18719

Browse files
committed
fix: use rank "first" instead of "dense"
"dense" rank gives the same rank for equal values which makes bars stay on top of each other
1 parent 71e4099 commit 0c18719

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

graphs/bar_chart_race.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def interpolated_df(self):
140140
.reset_index()
141141
)
142142
df["value"] = df["value"].fillna(0)
143-
df["rank"] = df.groupby("date")["value"].rank(method="dense", ascending=False)
143+
df["rank"] = df.groupby("date")["value"].rank(method="first", ascending=False)
144144
if "category" in self.df.columns:
145145
mapper = self.name_to_category()
146146
df["category"] = df["name"].apply(lambda name: mapper.get(name))
@@ -207,7 +207,7 @@ def values_by_date(self):
207207
last = last[~last.name.isin(grouped["name"])]
208208
if last.shape[0] > 0:
209209
last["rank"] = (
210-
last["value"].rank(method="dense", ascending=False)
210+
last["value"].rank(method="first", ascending=False)
211211
+ grouped[grouped["value"] > 0 ]["rank"].max()
212212
)
213213
last["value"] = 0.0

0 commit comments

Comments
 (0)