@@ -36,32 +36,43 @@ def filter_float(value):
3636def push_to_hf_dataset ():
3737 from run_all import FINAL_CSV_FILENAME , GITHUB_SHA
3838
39- # If there's an existing benchmark file, we should report the changes.
4039 csv_path = has_previous_benchmark ()
4140 if csv_path is not None :
4241 current_results = pd .read_csv (FINAL_CSV_FILENAME )
4342 previous_results = pd .read_csv (csv_path )
4443
45- # identify the numeric columns we want to annotate
4644 numeric_columns = current_results .select_dtypes (include = ["float64" , "int64" ]).columns
4745
48- # for each numeric column, append the old value in () if present
4946 for column in numeric_columns :
50- # coerce any “x units” strings back to float
51- prev_vals = previous_results [column ].map (filter_float )
52- # align indices in case rows were added/removed
53- prev_vals = prev_vals .reindex (current_results .index )
47+ # get previous values as floats, aligned to current index
48+ prev_vals = (
49+ previous_results [column ]
50+ .map (filter_float )
51+ .reindex (current_results .index )
52+ )
5453
55- # build the new string: "current_value (previous_value)"
56- curr_str = current_results [column ].astype (str )
57- prev_str = prev_vals .map (lambda x : f" ({ x } )" if pd .notnull (x ) else "" )
54+ # get current values as floats
55+ curr_vals = current_results [column ].astype (float )
5856
59- current_results [column ] = curr_str + prev_str
57+ # stringify the current values
58+ curr_str = curr_vals .map (str )
59+
60+ # build an appendage only when prev exists and differs
61+ append_str = prev_vals .where (
62+ prev_vals .notnull () & (prev_vals != curr_vals ),
63+ other = pd .NA
64+ ).map (lambda x : f" ({ x } )" if pd .notnull (x ) else "" )
65+
66+ # combine
67+ current_results [column ] = curr_str + append_str
6068
61- # overwrite the CSV
6269 current_results .to_csv (FINAL_CSV_FILENAME , index = False )
6370
64- commit_message = f"upload from sha: { GITHUB_SHA } " if GITHUB_SHA is not None else "upload benchmark results"
71+ commit_message = (
72+ f"upload from sha: { GITHUB_SHA } "
73+ if GITHUB_SHA is not None else
74+ "upload benchmark results"
75+ )
6576 upload_file (
6677 repo_id = REPO_ID ,
6778 path_in_repo = FINAL_CSV_FILENAME ,
0 commit comments