Pandas annotations#1035
Conversation
# Conflicts: # chainladder/core/pandas.py # chainladder/core/typing.py
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1035 +/- ##
==========================================
- Coverage 89.21% 89.19% -0.03%
==========================================
Files 89 89
Lines 5165 5173 +8
Branches 661 662 +1
==========================================
+ Hits 4608 4614 +6
- Misses 390 391 +1
- Partials 167 168 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
# Conflicts: # chainladder/core/typing.py
|
I'll fix that codecov comment in another PR, I think this one's already kind of big. |
| Examples | ||
| -------- | ||
|
|
||
| In a single-dimension case, an origin period will be dropped if it contains all NaN. |
There was a problem hiding this comment.
does this happen in the interior of the triangle?
There was a problem hiding this comment.
read the later example. we should clarify here that dropna doesn't work on the interior
|
|
||
| If both the earliest origin and development periods are all NaN, both will be dropped. | ||
|
|
||
| .. testcode:: |
There was a problem hiding this comment.
dropna isn't called in this example
| columns=['paid'], | ||
| cumulative=True | ||
| ) | ||
| print(tri.loc['abc']) |
| 1986 500.0 600.0 | ||
| 1987 500.0 NaN | ||
|
|
||
| In the case of a multi-dimensional Triangle, periods will only be dropped if their aggregate sum across |
There was a problem hiding this comment.
does this mean if i have a ground-up triangle and a deductible triangle in the same triangle, i could end up with origins or developments dropped?
| self.development <= ddim.max()) | ||
| ] | ||
| return obj[(self.origin >= min_odim) & (self.origin <= max_odim)] | ||
| obj = cast("TriangleProtocol", cast(object, obj)) |
There was a problem hiding this comment.
two casts (i guess technically 3) in 2 lines. why the differences?
- one upcasts to object but ones doesn't
- one casts to triangleprotocal one casts to triangle
| return obj | ||
|
|
||
| def head(self, n=5): | ||
| def head(self: TriangleProtocol, n=5): |
There was a problem hiding this comment.
is it too trivial to add n:int?
Summary of Changes
Add type annotations to
pandas.py. Add API reference examples toTrianglePandas.dropna(). This method really needed examples to illustrate its complex behavior. I'll try to stick to just 1 or 2 methods next time if they turn out to be as complex.Related GitHub Issue(s)
#486
#704
Additional Context for Reviewers
Removed line 303:
This line didn't do anything, it simplifies to self.values = self.values, so I removed it.
uv run pytest) and documentation changes (uv run jb build docs --builder=custom --custom-builder=doctest)Note
Medium Risk
fillnabehavior changes (mandatory value and altered inplace math) can affect callers that passedNoneor relied on the old frame-based fill path.Overview
Adds static typing across
chainladder/core/pandas.pyby typing mixin methods withTriangleProtocol, return/casthints for sparseCOOpaths, and expanded docstrings forplot,hvplot, and_get_axis.TriangleProtocolintyping.pyis expanded with properties and methods the pandas mixin relies on (origin,development,fillna, arithmetic, indexing, etc.) so type checkers can validateTrianglePandaswithoutSelfon older Python.Triangle.dropna()gains extensive doctest examples documenting edge-trimming behavior; implementation adds clarifying comments and explicitcaston sliced returns.fillnanow requires a fill value (TypeErrorifNone) and uses a simpler inplace update (self + fillinstead of an intermediateself + value * 0frame).fillzero/dropnareturn paths usecastfor checker clarity;to_framelong-format valuation assembly is refactored without intended output changes.Reviewed by Cursor Bugbot for commit 1fa4d77. Bugbot is set up for automated code reviews on this repo. Configure here.