Verify a pandas rewrite
verify_rewriteCheck that a pandas rewrite produces the same output as the original and measure whether it is faster before recommending it.
Instructions
Check that a pandas rewrite gives the same result as the original, and measure whether it is faster.
Use this before telling the user a rewrite is equivalent or faster; use check_code to find candidates. Runs setup once, then original and candidate on separate copies of its variables, compares each output strictly (type, dtype, index, names, NaN positions, exact values) and times both (median of repeated runs, about 2 s budget).
Side effects: executes the given code locally. original and candidate must be pure
computation (no file, network, subprocess or global-state calls, no unseeded randomness);
otherwise nothing runs and refused says why. The verdict holds for these inputs only.
verdict is "identical"; "scalar_types" (every value equal, but some scalars differ in
type, e.g. numpy.float64 vs float, listed in details.scalar_types; not identical);
"within_tolerance" (floats differ by at most rtol, largest difference reported); or
"different" (with where).
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"original": "<original>",
"candidate": "<candidate>"
},
"name": "verify_rewrite"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| rtol | No | Relative tolerance for floats. Results that differ by no more than this get within_tolerance instead of different. | |
| setup | No | Code run once to build representative inputs, e.g. a DataFrame with realistic size and dtypes. It may read files and use seeded randomness. Leave empty if original builds its own inputs. | |
| outputs | No | Names of the variables to compare. Default: the variables original assigns. | |
| original | Yes | The pandas code to replace, e.g. an iterrows loop. It can use the variables setup creates. | |
| candidate | Yes | The rewrite that should produce the same variables as original. |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||