Skip to content

Use header index to replace fixed column order#77

Merged
coketaste merged 1 commit intocoketaste/refactor-disfrom
coketaste/refactor-dis-debug
Mar 2, 2026
Merged

Use header index to replace fixed column order#77
coketaste merged 1 commit intocoketaste/refactor-disfrom
coketaste/refactor-dis-debug

Conversation

@coketaste
Copy link
Copy Markdown
Collaborator

Appended rows now match the existing header, model, performance, metric, and status show in the correct column

…performance, metric, and status show in the correct column
@coketaste coketaste requested review from Copilot and gargrahul March 2, 2026 19:40
@coketaste coketaste self-assigned this Mar 2, 2026
@coketaste coketaste merged commit 2177b68 into coketaste/refactor-dis Mar 2, 2026
2 checks passed
@coketaste coketaste deleted the coketaste/refactor-dis-debug branch March 2, 2026 19:41
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates performance result recording/display so appended perf.csv rows align with the existing file’s header schema (instead of relying on a fixed column order), ensuring key fields like model/performance/metric/status appear in the correct columns.

Changes:

  • In Kubernetes result collection, adjust successful run entries for multiple_results fallback so CLI display uses per-row perf data (by setting nodes=[]).
  • In Kubernetes perf.csv writing, detect and reuse an existing perf.csv header to map values by column name when appending.
  • In CLI utilities, improve formatting/handling of empty values and nan model names when rendering tables.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/madengine/deployment/kubernetes.py Reworks perf.csv appending logic to respect existing header order and tweaks result payload for multi-row fallback display.
src/madengine/cli/utils.py Improves table rendering robustness for empty values and nan model fields.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +3831 to +3841
file_exists = perf_csv_path.exists()
existing_header = None
if file_exists:
# Read existing header so we write in the same column order (fixes MAD-private
# and other repos that use a different perf.csv schema with more/different columns)
with open(perf_csv_path, "r", newline="", encoding="utf-8", errors="replace") as rf:
reader = csv.reader(rf)
existing_header = next(reader, None)
headers = existing_header if existing_header else default_headers
if file_exists and existing_header:
# Build row by name so model/performance/metric/status go to correct columns
Copy link

Copilot AI Mar 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If perf.csv exists but is empty (or the first row is blank), perf_csv_path.exists() will be True while existing_header is None/empty, which skips writeheader() and appends a data row without any header line. Consider treating an empty/invalid header as a new file (e.g., check stat().st_size == 0 or validate existing_header) and write default_headers before appending rows.

Copilot uses AI. Check for mistakes.
Comment on lines +3847 to +3854
with open(perf_csv_path, "a", newline="", encoding="utf-8") as f:
writer = csv.DictWriter(f, fieldnames=headers, extrasaction="ignore")
if not file_exists:
writer.writeheader()

# Write data row (only fields in headers will be written)
writer.writerow(perf_data)
if file_exists and existing_header:
csv.writer(f).writerow(row_to_write)
else:
writer.writerow(row_to_write)
Copy link

Copilot AI Mar 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This branch builds writer = csv.DictWriter(...) but then writes rows using csv.writer(f).writerow(...). Mixing DictWriter and writer can lead to subtle differences in quoting/dialect and makes the code harder to follow. Consider consistently using DictWriter.writerow(...) (it already respects fieldnames order and fills missing keys with restval) to write both new and existing-header rows.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants