Skip to content

Commit 087bed7

Browse files
committed
Fix score saving silent failures and attribute errors
- Add getattr safety checks for local_param_dict, final_column_list, and feature names to prevent crashes. - Fix typo in feature names attribute access (orignal -> original) with fallback. - Add console output for exceptions to ensure errors are visible during live runs. - Optimize initialization by removing redundant empty DataFrame creation.
1 parent a7171c4 commit 087bed7

1 file changed

Lines changed: 11 additions & 10 deletions

File tree

ml_grid/util/project_score_save.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,7 @@ def update_score_log(
188188

189189
# --- OPTIMIZATION: Construct dictionary first to avoid slow DataFrame element-wise setting ---
190190
row_data = {}
191-
column_list = _get_score_log_columns(list(global_params.metric_list.keys()))
192-
line = pd.DataFrame(data=None, columns=column_list)
191+
column_list = self.column_list
193192

194193
# --- OPTIMIZATION: Pre-process targets for faster metric calculation ---
195194
# Convert to numpy arrays to avoid pandas overhead in sklearn metrics
@@ -244,24 +243,25 @@ def update_score_log(
244243
accuracy = accuracy_score(y_test_np, best_pred_np)
245244

246245
# Populate row_data dictionary instead of repeated DataFrame indexing
247-
for key in ml_grid_object.local_param_dict:
246+
local_params = getattr(ml_grid_object, "local_param_dict", {})
247+
for key in local_params:
248248
# print(key)
249249
if key != "data":
250250
if key in column_list:
251-
row_data[key] = ml_grid_object.local_param_dict.get(key)
251+
row_data[key] = local_params.get(key)
252252
else:
253-
for key_1 in ml_grid_object.local_param_dict.get("data"):
253+
data_dict = local_params.get("data", {})
254+
for key_1 in data_dict:
254255
# print(key_1)
255256
if key_1 in column_list:
256-
row_data[key_1] = ml_grid_object.local_param_dict.get(
257-
"data"
258-
).get(key_1)
257+
row_data[key_1] = data_dict.get(key_1)
259258

260-
current_f = ml_grid_object.final_column_list
259+
current_f = getattr(ml_grid_object, "final_column_list", [])
261260
# current_f = list(self.X_test.columns)
262261
current_f_vector = []
263262
f_list = []
264-
for elem in ml_grid_object.orignal_feature_names:
263+
feature_names = getattr(ml_grid_object, "original_feature_names", getattr(ml_grid_object, "orignal_feature_names", []))
264+
for elem in feature_names:
265265
if elem in current_f:
266266
current_f_vector.append(1)
267267
else:
@@ -376,5 +376,6 @@ def update_score_log(
376376
except Exception as e:
377377
logger = logging.getLogger("ml_grid")
378378
logger.error(f"Failed to update score log: {e}", exc_info=True)
379+
print(f"Error updating score log: {e}")
379380
if global_params.error_raise:
380381
raise e

0 commit comments

Comments
 (0)