Commit 3968f0c
PR #464 R2 polish: thread df_name through agent_workflow (codex P1)
CI codex review on the rebased SHA flagged a newly-identified P1:
agent_workflow() hardcoded the dataframe symbol `df` into every emitted
call. A caller who does `panel = pd.read_parquet(...)` and then calls
diff_diff.agent_workflow(panel, ...) gets back a script that references
`df` and NameErrors on first execution.
Fix: add `df_name: str = "df"` parameter, threaded into:
- profile_call (`diff_diff.profile_panel({df_name}, ...)`)
- both Step 3 fit example branches (CallawaySantAnna + DifferenceInDifferences)
Default `df_name="df"` preserves prior behavior verbatim. Caller binds
their dataframe to any identifier and passes the name; emitted script
runs in their namespace without renaming.
Tests added:
- `test_df_name_templates_into_script`: default vs `df_name="panel"`,
static AST scan confirms no bare `df` Name node remains.
- `test_df_name_panel_script_executes_in_panel_namespace`: stubs
`diff_diff` with MagicMock, exec's the panel-named script in a
namespace where `panel` exists and `df` does not — NameError on
the dataframe symbol would fail the test.
Total tests: 21 → 23 in test_agent_workflow.py.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent e1d0f33 commit 3968f0c
2 files changed
Lines changed: 87 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
69 | 69 | | |
70 | 70 | | |
71 | 71 | | |
| 72 | + | |
72 | 73 | | |
73 | 74 | | |
74 | 75 | | |
| |||
99 | 100 | | |
100 | 101 | | |
101 | 102 | | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
102 | 115 | | |
103 | 116 | | |
104 | 117 | | |
| |||
140 | 153 | | |
141 | 154 | | |
142 | 155 | | |
143 | | - | |
| 156 | + | |
144 | 157 | | |
145 | 158 | | |
146 | 159 | | |
| |||
163 | 176 | | |
164 | 177 | | |
165 | 178 | | |
166 | | - | |
| 179 | + | |
167 | 180 | | |
168 | 181 | | |
169 | 182 | | |
| |||
178 | 191 | | |
179 | 192 | | |
180 | 193 | | |
181 | | - | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
182 | 197 | | |
183 | 198 | | |
184 | 199 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
242 | 242 | | |
243 | 243 | | |
244 | 244 | | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
245 | 314 | | |
246 | 315 | | |
247 | 316 | | |
| |||
0 commit comments