Skip to content

Commit 1731f6c

Browse files
committed
feat: use mape as deviation indicator
1 parent 58b1ead commit 1731f6c

File tree

1 file changed

+23
-8
lines changed

1 file changed

+23
-8
lines changed

draft_comment.py

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
import argparse
12
import os
3+
4+
import numpy as np
25
import pandas as pd
3-
import argparse
46

57

68
def get_plot_comparison_table_html(commit_id, plots):
@@ -22,7 +24,7 @@ def get_plot_comparison_table_html(commit_id, plots):
2224

2325

2426
def get_csv_comparison_table_html(dir_base, dir_feature):
25-
status_not_equal = "Changed :warning:"
27+
status_not_equal = ":warning:"
2628
status_missing = "Missing :warning:"
2729
status_new = "New :warning:"
2830

@@ -48,13 +50,26 @@ def get_csv_comparison_table_html(dir_base, dir_feature):
4850
df1 = pd.read_csv(path_in_a)
4951
df2 = pd.read_csv(path_in_b)
5052

51-
try:
52-
pd.testing.assert_frame_equal(df1, df2)
53+
if df1.equals(df2):
5354
equal.append(f"<tr><td>{relative_path}</td><td>Equal</td></tr>\n")
54-
except AssertionError:
55-
not_equal.append(
56-
f"<tr><td>{relative_path}</td><td>{status_not_equal}</td></tr>\n"
57-
)
55+
else:
56+
numeric_columns = df1.select_dtypes(include="number").columns
57+
df1_num = df1[numeric_columns].replace(0, np.nan)
58+
df2_num = df2[numeric_columns].replace(0, np.nan)
59+
mape = ((abs((df1_num - df2_num) / df1_num)).mean().mean()) * 100
60+
61+
if mape > 1e-6:
62+
not_equal.append(
63+
f"<tr><td>{relative_path}</td><td>{status_not_equal} (MAPE: {mape:.2e}%)</td></tr>\n"
64+
)
65+
elif pd.isna(mape):
66+
not_equal.append(
67+
f"<tr><td>{relative_path}</td><td>{status_not_equal} (Type or nan mismatch)</td></tr>\n"
68+
)
69+
else:
70+
equal.append(
71+
f"<tr><td>{relative_path}</td><td>Equal</td></tr>\n"
72+
)
5873

5974
# Check for new files in directory b
6075
for root, dirs, files in os.walk(dir_feature):

0 commit comments

Comments
 (0)