Add clampvalues and filldown transforms#692
Conversation
- Implements ClampValuesView following petl's Table subclass pattern - Handles None values, floats, negative ranges, and boundary equality - Raises ValueError for invalid ranges (low > high) and missing fields - 10 unit tests covering normal cases and edge cases
- Implements FillDownView following petl's Table subclass pattern - Supports filling multiple fields in a single call - Leading None values remain None until a non-None value is seen - Raises FieldSelectionError for missing fields - 9 unit tests covering normal cases and edge cases
Review Summary by QodoAdd clampvalues and filldown data transformation functions
WalkthroughsDescription• Add clampvalues transform to restrict numeric field values within range • Add filldown transform to propagate last non-None value downward • Implement both transforms following petl's Table subclass pattern • Register both functions in transform module with comprehensive test coverage Diagramflowchart LR
A["Input Table"] -->|clampvalues| B["Clamped Values<br/>low ≤ val ≤ high"]
A -->|filldown| C["Filled Down<br/>None → last value"]
B --> D["Output Table"]
C --> D
File Changes1. petl/transform/clamp.py
|
Code Review by Qodo
1. Filldown export shadowed
|
| from petl.transform.clamp import clampvalues | ||
|
|
||
| from petl.transform.filldown import filldown | ||
|
|
There was a problem hiding this comment.
1. Filldown export shadowed 🐞 Bug ≡ Correctness
petl.transform.__init__ imports filldown from the new petl/transform/filldown.py, but later re-imports filldown from petl/transform/fills.py, overwriting the new symbol. As a result, the newly added filldown implementation is effectively unused and untested via the public API.
Agent Prompt
### Issue description
`petl/transform/__init__.py` imports `filldown` twice, and the later import from `petl.transform.fills` overwrites the new `petl.transform.filldown.filldown`. This makes the newly added module effectively unreachable from `import petl as etl`.
### Issue Context
There is already an existing `filldown` implementation in `petl/transform/fills.py` (including `Table.filldown = filldown`). The PR adds a second implementation under the same name.
### Fix Focus Areas
- petl/transform/__init__.py[14-37]
- petl/transform/fills.py[10-103]
- petl/transform/filldown.py[1-80]
### Suggested resolution paths
- **Preferred:** Delete `petl/transform/filldown.py` and remove `from petl.transform.filldown import filldown` from `petl/transform/__init__.py` (keep tests if they are intended to validate the existing `fills.filldown`).
- **Alternative (if you truly want a new implementation):** Stop importing `filldown` from `petl.transform.fills` (or rename one of the functions), then ensure the exported one matches petl conventions (supports `missing=`, supports filling all fields when none specified, uses `petl.compat.next`, and registers `Table.filldown`).
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
Summary
This PR adds two new data transformation functions to petl:
1.
clampvalues(table, field, low, high)Restricts numeric values in a field to a [low, high] range.
loware raised tolowhighare lowered tohigh2.
filldown(table, *fields)Propagates the last observed non-None value downward within one or more fields.
Changes
petl/transform/clamp.py— new filepetl/transform/filldown.py— new filepetl/test/transform/test_clamp.py— 10 unit tests, all passingpetl/test/transform/test_filldown.py— 9 unit tests, all passingpetl/transform/__init__.py— registered both functionsTests
508 passed, 18 skipped (0 failures)