From 5ac42644704ed49ea44a561c76f9e8c2c2fea937 Mon Sep 17 00:00:00 2001 From: Dylan De Faoite Date: Mon, 2 Feb 2026 17:27:05 +0000 Subject: [PATCH] fix: server error when no comments exist --- server/stat_gen.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/server/stat_gen.py b/server/stat_gen.py index 9e3caea..1178f6a 100644 --- a/server/stat_gen.py +++ b/server/stat_gen.py @@ -183,6 +183,11 @@ class StatGen: .unstack(fill_value=0) ) + # ensure columns always exist + for col in ("post", "comment"): + if col not in per_user.columns: + per_user[col] = 0 + per_user["comment_post_ratio"] = per_user["comment"] / per_user["post"].replace(0, 1) per_user["comment_share"] = per_user["comment"] / (per_user["post"] + per_user["comment"]).replace(0, 1) per_user = per_user.sort_values("comment_post_ratio", ascending=True)