Skip to content

Add Triangle.ffill() to forward-fill along the origin/development axes - #1302

Open
Abhayindia wants to merge 1 commit into
casact:mainfrom
Abhayindia:feature/triangle-ffill
Open

Add Triangle.ffill() to forward-fill along the origin/development axes#1302
Abhayindia wants to merge 1 commit into
casact:mainfrom
Abhayindia:feature/triangle-ffill

Conversation

@Abhayindia

Copy link
Copy Markdown
Contributor

Closes #1030.

Adds Triangle.ffill(axis), mirroring pandas' ffill but along the origin or development axis, and never writing a value into a cell that hasn't been valued yet.

On the semantics question I asked in #1030 and never got an answer to: genedan's own worked example in the issue answers it, once you check it against the triangle's actual nan_triangle. In his axis=3 sketch, 1987 at ages 36/48 stays missing even though 1300 precedes it - because those cells are beyond the triangle's evaluation date, not because they're a "later" NaN. His axis=4 example (there's no axis 4, so I read it as origin) is consistent with the same rule the whole way through: 1988 at ages 24-48 stays missing for the same reason. There's exactly one cell in the whole issue that breaks the pattern - 1986 at age 48 in the axis=3 example, which the sketch fills to 1100 even though that cell is also beyond the evaluation date. Given eleven other cells across both examples agree and only this one doesn't, I'm reading it as a typo in the hand-written sketch rather than the intended behavior, and implemented the self-consistent rule: fill forward within the observed triangle, leave everything outside it untouched.

Docstring example reuses that same triangle from the issue (with the corrected 1986/48 cell) for both axes. Tests cover the development and origin directions, that it returns a new object rather than mutating in place, and the axis validation.

$ pytest chainladder/core/tests/test_triangle.py -q
353 passed, 1 skipped in 813s

@github-actions

github-actions Bot commented Sep 5, 2026

Copy link
Copy Markdown

Pyright Type Completeness

View the full pyright --verifytypes output for this commit

Project (full chainladder package, at this PR's head): 15.6% of exported symbols fully typed (216 / 1387)

Known Ambiguous Unknown Total
Project (head) 216 111 1060 1387

Other symbols referenced but not exported by chainladder: 13

Known Ambiguous Unknown Total
Other (head) 3 1 9 13

Symbols without documentation:

  • Functions without docstring: 325
  • Functions without default param: 0
  • Classes without docstring: 10

Patch (exported symbols added or changed by this PR): 60.0% fully typed (3 / 5)

Known Ambiguous Unknown Total
Patch 3 0 2 5
Patch symbol details
Symbol Status Change
chainladder.core.tests.test_triangle.test_ffill_development_axis ✅ known new
chainladder.core.tests.test_triangle.test_ffill_does_not_mutate_original ✅ known new
chainladder.core.tests.test_triangle.test_ffill_invalid_axis_raises ❌ unknown new
chainladder.core.tests.test_triangle.test_ffill_origin_axis ✅ known new
chainladder.core.triangle.Triangle.ffill ❌ unknown new

@codecov

codecov Bot commented Sep 5, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.70%. Comparing base (5df817f) to head (fdf0a10).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1302      +/-   ##
==========================================
+ Coverage   91.67%   91.70%   +0.03%     
==========================================
  Files          93       93              
  Lines        5441     5462      +21     
  Branches      702      704       +2     
==========================================
+ Hits         4988     5009      +21     
  Misses        328      328              
  Partials      125      125              
Flag Coverage Δ
unittests 91.70% <100.00%> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Triangle.ffill()

1 participant