nan_triangle 1D logic overhaul#702
Conversation
…y with setter. Added is_pattern and is_ultimate abstract properties to TriangleBase
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #702 +/- ##
==========================================
+ Coverage 85.08% 85.12% +0.03%
==========================================
Files 85 85
Lines 4896 4909 +13
Branches 629 629
==========================================
+ Hits 4166 4179 +13
Misses 521 521
Partials 209 209
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
@danielfong-act, thanks for going the extra mile and figuring out the abstract class features! I just have a few minor requests:
|
|
sure, cleaner code is always better |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 2efef59. Configure here.
|
|
||
| @property | ||
| def is_ultimate(self): | ||
| def is_ultimate(self) -> np.bool: |
There was a problem hiding this comment.
Reviewer requested -> bool but got -> np.bool
Low Severity
The is_ultimate property uses -> np.bool as the return type annotation. The PR reviewer explicitly requested -> bool type hints for the getter and setter. Additionally, np.bool was removed in numpy 1.24 and only restored in numpy 2.0, making it an unreliable alias. The function actually returns a Python bool (from int > 0), so the annotation is also technically inaccurate. This violates the reviewer's explicit request: "Add type hints to the getter and setter (-> bool)".
Reviewed by Cursor Bugbot for commit 2efef59. Configure here.
|
Could you put in three more bool return type hints on these lines? 318 Also, please add a unit test for a 2x2 triangle. I think the one in #692 would be a good one to use. |
|
Sure, but does using numpy.bool_ (where appropriate) bother you? e.g. |
|
numpy.bool_ works for me. |
…ngles calling cum_to_incr().
|
I left the setter alone since python really seems to discourage having setters returning anything. I also don't think people expect a return in the context of a property assignment. |
|
Closes #692. Good job! |


Fixes #692
is_patternas a property inTriangle. Adds_patternas an internal attribute.is_patternandis_ultimatetoTriangleBase.TriangleBaseis now an abstract class.nan_triangleto check explicitly for pattern/ultimate vectors, instead of checking for any 1D Triangles.see this post.
cum_to_incr()mishandles 2x2 triangles because it passesnan_trianglea one dimensional triangle (corresponding to the latter development period), and receives back a full 1D triangle of ones. This causescum_to_incr()to ignore valuation information and populate the lower right corner of the triangle with a negative incremental value.In addition to the test suite, I tested this PR with this snippet of code pulled from the issue discussion:
I also ensured that development estimators that set is_pattern (e.g. ClarkLDF) continue to function properly.
This PR will restrict
nan_triangleto only return 1D triangles of ones for pattern and ultimate triangles. If I'm missing a case, please let me know.Note
Medium Risk
Touches core triangle masking used across arithmetic and conversions, so it may subtly change results for pattern/ultimate workflows even though coverage includes a targeted regression test.
Overview
Fixes a
cum_to_incr()regression on 2x2 triangles by changingnan_triangleto return an all-ones mask only for pattern vectors and ultimate vectors, rather than for any 1D triangle.Promotes
TriangleBaseto an abstract base class by requiringis_pattern/is_ultimateproperties, and reworksTriangle.is_patternto use an internal_patternattribute with a property/setter. Adds a regression test covering the 2x2 conversion case.Reviewed by Cursor Bugbot for commit a25ea4c. Bugbot is set up for automated code reviews on this repo. Configure here.