Commit f808ae6
committed
efficient-did: make set_params atomic — rollback all attribute mutations on validation failure
Previously, EfficientDiD.set_params iterated over the kwargs and called
setattr() before invoking _validate_params(). A rejected batched call
such as set_params(vcov_type="classical", alpha=0.1, anticipation=2)
raised on validation but left every kwarg in the partially-mutated
state — the rejected vcov_type plus the otherwise-valid alpha and
anticipation. Callers that catch ValueError and continue using the
estimator would then operate on a silently corrupted parameter
configuration, defeating the eager-validation contract introduced when
_validate_vcov_type was wired into _validate_params.
Fix: snapshot original attribute values for every kwarg before applying
mutations, run validation, and on exception restore the snapshot before
re-raising. The snapshot pass also moves the "Unknown parameter" check
ahead of any mutation so that even unknown-name rejections leave the
estimator untouched.
Regression test added: test_set_params_rollback_on_validation_failure
fires the 3-kwarg batched call and pins all three attribute values to
their pre-call snapshot after the raise.1 parent 79f428d commit f808ae6
2 files changed
Lines changed: 40 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
351 | 351 | | |
352 | 352 | | |
353 | 353 | | |
354 | | - | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
355 | 370 | | |
356 | | - | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
357 | 376 | | |
358 | | - | |
359 | | - | |
360 | | - | |
| 377 | + | |
361 | 378 | | |
362 | 379 | | |
363 | 380 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2521 | 2521 | | |
2522 | 2522 | | |
2523 | 2523 | | |
| 2524 | + | |
| 2525 | + | |
| 2526 | + | |
| 2527 | + | |
| 2528 | + | |
| 2529 | + | |
| 2530 | + | |
| 2531 | + | |
| 2532 | + | |
| 2533 | + | |
| 2534 | + | |
| 2535 | + | |
| 2536 | + | |
| 2537 | + | |
| 2538 | + | |
| 2539 | + | |
| 2540 | + | |
| 2541 | + | |
2524 | 2542 | | |
2525 | 2543 | | |
2526 | 2544 | | |
| |||
0 commit comments