Skip to content

perf: iterate reason codes via to_dict('records') instead of iterrows#13

Merged
AmirhosseinHonardoust merged 1 commit into
mainfrom
perf/reason-codes-vectorize-iteration
Jun 19, 2026
Merged

perf: iterate reason codes via to_dict('records') instead of iterrows#13
AmirhosseinHonardoust merged 1 commit into
mainfrom
perf/reason-codes-vectorize-iteration

Conversation

@AmirhosseinHonardoust

Copy link
Copy Markdown
Owner

add_reason_codes iterated rows with DataFrame.iterrows(), which builds
a pandas Series per row, and reason_codes_for_row then re-wrapped each
row in pd.Series. Both are unnecessary: the logic only uses row.get(),
which dicts support directly.

  • Iterate df.to_dict("records") and pass plain dict rows.
  • Drop the per-row pd.Series(row) construction; reason_codes_for_row
    now accepts a Series or any mapping unchanged.

No behavior change (O(n) before and after; this is a constant-factor
speedup, not an algorithmic fix).

Verified locally:

  • Reason codes identical for Series-input vs dict-input across all 700
    rows of the scored test set; full scored CSV byte-identical (md5
    unchanged).
  • ~6x faster on a 20k-row benchmark (0.99s -> 0.17s).
  • ruff/black/mypy clean; 34/34 tests pass.

@AmirhosseinHonardoust AmirhosseinHonardoust self-assigned this Jun 19, 2026
@AmirhosseinHonardoust AmirhosseinHonardoust added the enhancement New feature or request label Jun 19, 2026
@AmirhosseinHonardoust
AmirhosseinHonardoust merged commit 75f0964 into main Jun 19, 2026
8 checks passed
@AmirhosseinHonardoust
AmirhosseinHonardoust deleted the perf/reason-codes-vectorize-iteration branch June 19, 2026 22:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant