Skip to content

Allow development to accept an age in months relative to origin - #1229

Open
Abhayindia wants to merge 1 commit into
casact:mainfrom
Abhayindia:fix/development-1970-false-positive
Open

Allow development to accept an age in months relative to origin#1229
Abhayindia wants to merge 1 commit into
casact:mainfrom
Abhayindia:fix/development-1970-false-positive

Conversation

@Abhayindia

Copy link
Copy Markdown
Contributor

Closes #1094 (the enhancement route agreed with @henrydingliu in that thread).

_to_datetime tries %Y%m, %Y, %Y-%m-%d and then falls through to a bare pd.to_datetime, which for a numeric column silently reads the values as nanoseconds since epoch. That collapsed age-lag columns like [12, 24, 36] to 1970-01-01, and the old guard just checked whether the result landed in 1970 - so a triangle whose development really is the year 1970 got the same error.

This replaces that with a check at the point of parsing: if none of the explicit formats matched and the column is numeric, it's an age in months. _init_development then resolves each value to the valuation date that many months after the start of that row's origin period. Ages are measured from the origin period start (using the constructor's own origin_grain, so mid-period origin dates and fiscal-year anchors line up), not the literal recorded origin date. Bare years still match %Y and are untouched. Non-numeric unparseable input still raises, with the same message as before. Semiannual grains only support the calendar Jan/Jul anchor; a non-calendar one raises a clear error rather than guessing.

Verified:

$ python -m pytest chainladder/core/tests/test_triangle.py -q
312 passed, 1 skipped in 100.59s

Full suite was 1091 passed / 8 skipped when I posted the branch on the issue.

@github-actions

github-actions Bot commented Aug 27, 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.3% of exported symbols fully typed (211 / 1379)

Known Ambiguous Unknown Total
Project (head) 211 111 1057 1379

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): 100.0% fully typed (3 / 3); 1 no longer exported

Known Ambiguous Unknown Total
Patch 3 0 0 3
Patch symbol details
Symbol Status Change
chainladder.core.tests.test_triangle.test_set_development_age_in_months ✅ known new
chainladder.core.tests.test_triangle.test_set_development_age_respects_mid_period_origin ✅ known new
chainladder.core.tests.test_triangle.test_set_development_bare_years_unaffected_by_age_support ✅ known new
chainladder.core.tests.test_triangle.test_set_development_age_instead_of_date_raises no longer exported (was ✅ known)

@henrydingliu

Copy link
Copy Markdown
Member

just unblocked tests. expecting ruff and codecov fails.

@codecov

codecov Bot commented Aug 27, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 62.50000% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.61%. Comparing base (16460a8) to head (4a0ad6d).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
chainladder/core/base.py 62.50% 4 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1229      +/-   ##
==========================================
- Coverage   91.70%   91.61%   -0.10%     
==========================================
  Files          93       93              
  Lines        5435     5448      +13     
  Branches      699      703       +4     
==========================================
+ Hits         4984     4991       +7     
- Misses        327      331       +4     
- Partials      124      126       +2     
Flag Coverage Δ
unittests 91.61% <62.50%> (-0.10%) ⬇️

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.

@Abhayindia
Abhayindia force-pushed the fix/development-1970-false-positive branch from 87a5a8f to 1ac7da2 Compare August 27, 2026 21:54
@henrydingliu

Copy link
Copy Markdown
Member

moving to draft due to conflicts

@henrydingliu
henrydingliu marked this pull request as draft August 30, 2026 15:04
@Abhayindia

Abhayindia commented Aug 31, 2026

Copy link
Copy Markdown
Contributor Author

@henrydingliu the conflict is genedan's #1088, which added test_set_development_age_instead_of_date_raises - it asserts development-as-age raises ValueError, the opposite of what this PR does. @genedan do you still want the age-in-months feature from #1094, or has the direction shifted to "reject ages with a clear error"? happy to rework either way.

@Abhayindia
Abhayindia marked this pull request as ready for review August 31, 2026 22:38
@henrydingliu

Copy link
Copy Markdown
Member

good to deprecate test_set_development_age_instead_of_date_raises

@Abhayindia
Abhayindia force-pushed the fix/development-1970-false-positive branch from 1ac7da2 to 4a0ad6d Compare September 1, 2026 12:08
@Abhayindia

Copy link
Copy Markdown
Contributor Author

rebased on main - kept the age-in-months tests and dropped test_set_development_age_instead_of_date_raises per your call. ruff check clean; the ruff format fail is the same pre-existing whole-file base.py/test_triangle.py nonconformance.

@henrydingliu

Copy link
Copy Markdown
Member

the ruff format fail is the same pre-existing whole-file base.py/test_triangle.py nonconformance

is it a bug that the per-file ignore didn't work?

codecov still shows uncovered changes

@Abhayindia

Copy link
Copy Markdown
Contributor Author

per-file-ignores only apply to ruff check, not ruff format - the formatter has no per-file exclusion, so any PR that touches base.py trips the whole-file format check. base.py needs ~200 lines of reformatting, which really belongs in its own cleanup PR (same situation #1216 describes). I can run ruff format on test_triangle.py here (~60 lines) if that helps, but base.py I'd rather leave.

codecov: the uncovered lines are the semiannual-origin (2Q) branch of the age path - it only triggers for a non-default semiannual anchor and is awkward to exercise in a unit test. Happy to add one if you want it covered.

@henrydingliu

Copy link
Copy Markdown
Member

understood on ruff format.

it only triggers for a non-default semiannual anchor and is awkward to exercise in a unit test.

does the new prism triangles help?

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.

Hardcoded 1970 value in core/base.py

2 participants