Fix Col.prev()/next() losing cross-frame reference, value_color() chaining, Neg type hint#1
Conversation
…eturn, Neg.compute() type hint - Col.prev() and Col.next() now preserve the from_ parameter for cross-frame references. Previously, calling .prev(1) or .next(1) on a Col with from_= some_other_frame would silently drop the cross-frame reference, causing formulas to reference the wrong ExcelFrame. - TableStyler.value_color() now returns Self to enable method chaining, consistent with all other fmt_* methods. - Fixed Neg.compute() return type annotation from None to Any. - Added tests for cross-frame prev/next and value_color chaining. Co-Authored-By: albert.han+coggittest@windsurf.com <yjhan96@gmail.com>
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
|
|
||
| def prev(self, offset: int) -> "Col": | ||
| return Col(self._col_name, offset=-offset) | ||
| return Col(self._col_name, from_=self.from_, offset=-offset) |
There was a problem hiding this comment.
Why are we adding this param here?
There was a problem hiding this comment.
Before this fix, prev() and next() were creating a new Col without forwarding self.from_. This means if you had a cross-frame reference like:
el.col("price", from_=other_frame).prev(1)The .prev(1) call would produce Col("price", offset=-1) — note from_ defaults to None. So instead of looking up the previous row in other_frame, it would look up the previous row in the current frame, which either references the wrong data or fails silently (e.g., if the current frame doesn't even have a "price" column).
Adding from_=self.from_ ensures the cross-frame reference is preserved through prev()/next() calls. Without from_, these methods are only correct for same-frame references.
Review SummaryAll three fixes are correct, well-scoped, and well-tested. CI is green. LGTM — ready to merge. Fix 1:
|
|
Closing due to inactivity for more than 7 days. Configure here. |
Summary
Fixes three bugs found during code audit:
Col.prev()andCol.next()silently dropfrom_parameter (logic bug, highest impact): When aColis created withfrom_=other_frameto reference a different ExcelFrame, calling.prev(1)or.next(1)would create a newColwithout passingfrom_through. This caused cross-frame references to silently reference the wrong ExcelFrame, producing incorrect formulas. Introduced in commitab6d4f0whenfrom_was added toCol.TableStyler.value_color()missingreturn self: All otherfmt_*methods returnSelffor method chaining, butvalue_color()returnedNone, breaking chains likestyler.value_color(...).fmt_number(...).Neg.compute()return type annotation-> None: Should be-> Anylike all othercompute()methods. The function actually returns a numeric value.Review & Testing Checklist for Human
prev()/next()works in a real multi-table scenario (e.g., the DCF or mortgage example with cross-table references using.prev())value_color()chaining works:styler.value_color(columns=["x"]).fmt_number(columns=["y"])pytest test/andpyright— both pass cleanlyNotes
Link to Devin session: https://staging.itsdev.in/sessions/bffcb71e53fc4b468c099a4abebd2377
Requested by: @yjhan96