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

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.0% of exported symbols fully typed (204 / 1357)

Known Ambiguous Unknown Total
Project (head) 204 111 1042 1357

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: 323
  • 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 64.70588% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.23%. Comparing base (d182ae4) to head (87a5a8f).
⚠️ Report is 8 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.31%   91.23%   -0.09%     
==========================================
  Files          91       92       +1     
  Lines        5434     5451      +17     
  Branches      700      704       +4     
==========================================
+ Hits         4962     4973      +11     
- Misses        336      340       +4     
- Partials      136      138       +2     
Flag Coverage Δ
unittests 91.23% <64.70%> (-0.09%) ⬇️

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.

Hardcoded 1970 value in core/base.py

2 participants