Commit ae18644
authored
fix(generate): fail loudly on a headerless .wgt.csv source, don't misparse it (#194)
## Summary
- Reported ask was ".wgt.csv weighted source at the attribute level, not
just whole-entity" - turned out inverted: `<key source="x.wgt.csv">`
(attribute level) already applies weights correctly (verified
statistically: 79% vs 80% expected on a 3000-row sample). The real,
confirmed bug is the opposite end: `<generate source="x.wgt.csv">`
(entity level) silently misparses the headerless value|weight format as
a headered CSV, producing nonsense column names and fewer rows than the
file has.
- Full fix (wiring `WeightedEntityDataSource` into `<generate>`'s
chunked pagination) is bigger and riskier than it first looks:
`ChunkSourceReader`'s `loads_all` path (what a weighted source would
need) re-permutes its pool via `get_distributed_data`/`get_unique_data`
- reusing it would double-apply selection on top of already-weighted
draws, and a naive per-page rebuild risks silently duplicating rows
across multiprocess workers. That's real surgery on shared pagination
code, scoped as follow-up work, not this PR.
- This PR only fails loudly instead of silently producing garbage for
`.wgt.csv` at `<generate>`-level.
- `.wgt.ent.csv` (a normal headered CSV with an extra "weight" column)
is explicitly NOT touched - reading it plainly (no resampling, weight
column as literal data) is coherent and an existing test
(`test_source_script/test_iterate_source_scripted.xml`) already relies
on exactly that for an unrelated feature. Confirmed it still passes.
## Test plan
- [x] TDD: failing tests for both `.wgt.csv`-must-raise and
`.wgt.ent.csv`-must-still-read-plainly, confirmed RED/GREEN.
- [x] Existing `test_iterate_source_script` (which reads a
`.wgt.ent.csv`-named file for an unrelated reason) still passes.
- [x] Full suite: 1428 passed, 15 skipped.
- [x] mypy/ruff clean.1 parent 0a5e4f3 commit ae18644
6 files changed
Lines changed: 65 additions & 0 deletions
File tree
- datamimic_ce/tasks
- tests_ce/integration_tests/test_generate_wgt_source_guard
- data
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
344 | 344 | | |
345 | 345 | | |
346 | 346 | | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
347 | 361 | | |
348 | 362 | | |
349 | 363 | | |
| |||
Lines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
Lines changed: 3 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
Lines changed: 3 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
Lines changed: 3 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
Lines changed: 40 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
0 commit comments