Skip to content

docs: add Triangle arithmetic examples (#704) - #1213

Merged
henrydingliu merged 5 commits into
casact:mainfrom
EKtheSage:docs/704-dunders-examples
Aug 14, 2026
Merged

docs: add Triangle arithmetic examples (#704)#1213
henrydingliu merged 5 commits into
casact:mainfrom
EKtheSage:docs/704-dunders-examples

Conversation

@EKtheSage

Copy link
Copy Markdown
Contributor

Summary of Changes

  • Add doctest Examples for Triangle.__add__, .__sub__, .__mul__, and .__truediv__ in chainladder/core/dunders.py.
  • Include __add__ / __sub__ / __mul__ / __truediv__ as special-members on the inherited-class autosummary template so the operators appear on the Triangle API page.
  • Cover scalar arithmetic and column-ratio division (paid / incurred).

Related GitHub Issue(s)

Additional Context for Reviewers

Bite-sized core-module follow-up for #704. Companions: #1208 (slice), #1209 (io), #1210 (display).

Checklist

  • I passed tests locally for both code (uv run pytest) and documentation changes (uv run --directory docs jb build . --builder=custom --custom-builder=doctest)

Made with Cursor

Co-authored-by: Cursor <cursoragent@cursor.com>
@github-actions

github-actions Bot commented Aug 13, 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.1% of exported symbols fully typed (201 / 1333)

Known Ambiguous Unknown Total
Project (head) 201 111 1021 1333

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: 321
  • Functions without default param: 0
  • Classes without docstring: 10

Patch (exported symbols added or changed by this PR): no exported symbol type-completeness changes detected.

@codecov

codecov Bot commented Aug 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.25%. Comparing base (272cbe1) to head (ccf54c0).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1213      +/-   ##
==========================================
- Coverage   91.25%   91.25%   -0.01%     
==========================================
  Files          91       91              
  Lines        5400     5399       -1     
  Branches      691      691              
==========================================
- Hits         4928     4927       -1     
  Misses        338      338              
  Partials      134      134              
Flag Coverage Δ
unittests 91.25% <100.00%> (-0.01%) ⬇️

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.

.. testsetup::

import chainladder as cl
tri = cl.Triangle(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should tri be in testcode instead?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved. testsetup is only import chainladder as cl; the Triangle is built in testcode.

@henrydingliu

Copy link
Copy Markdown
Member

macro comment. i don't see __add__ listed in pandas. instead, there is an equivalent dataframe function .add.

@kennethshsu @genedan @priyam0k should we follow pandas?

… testcode.

testsetup stays as the chainladder import only, matching the other API doctest examples.

Co-authored-by: Cursor <cursoragent@cursor.com>
@EKtheSage

Copy link
Copy Markdown
Contributor Author

On following pandas DataFrame.add: Triangle has no .add / .sub / .mul / .div. The operators are the public arithmetic API, so :special-members: is how those examples show up on the Triangle page.

Leaving whether to add pandas-style .add methods to the people tagged above.

@henrydingliu

Copy link
Copy Markdown
Member

On following pandas DataFrame.add: Triangle has no .add / .sub / .mul / .div. The operators are the public arithmetic API, so :special-members: is how those examples show up on the Triangle page.

Leaving whether to add pandas-style .add methods to the people tagged above.

yeah, that's what I mean, taking inspiration from your other PR on slice.py

@genedan

genedan commented Aug 13, 2026

Copy link
Copy Markdown
Member

I think these examples are useful. I think dunders and arithmetic operators fall under "advanced programming for actuaries" territory, so it'd be helpful for them to see how the operators are related to the dunders, and how we program them into the package.

@priyam0k

Copy link
Copy Markdown
Collaborator

Agree with Gene. Documenting dunders makes sense here since operators are Triangle's current arithmetic API.

The main benefit of pandas .add() would be supporting fill_value for mismatched triangles, but we can track .add() in a separate feature issue if needed.

@henrydingliu

Copy link
Copy Markdown
Member

sounds good.

all set on docstrings.

ruff fix pls?

also outstanding question on api template change

…ate.

The ruff workflow lints touched files with per-file ignores cleared. The template unions documented Triangle attrs and arithmetic dunders so sibling casact#704 PRs do not clobber each other on merge.

Co-authored-by: Cursor <cursoragent@cursor.com>
EKtheSage added a commit to EKtheSage/chainladder-python that referenced this pull request Aug 14, 2026
… autosummary template.

The ruff workflow lints touched files with per-file ignores cleared. The template now unions the documented Triangle attrs and arithmetic dunders so casact#1208, casact#1212, and casact#1213 do not clobber each other on merge.

Co-authored-by: Cursor <cursoragent@cursor.com>
@EKtheSage

Copy link
Copy Markdown
Contributor Author

Gene/Priyam: keeping the dunder examples.

Ruff: E721/E722/F841 in dunders.py are fixed and the file ignore is dropped.

The autosummary template is the same union as #1208/#1211/#1212, so the last of these PRs to merge does not wipe documented indexers, shape attrs, or arithmetic dunders.

EKtheSage added a commit to EKtheSage/chainladder-python that referenced this pull request Aug 14, 2026
The last merge of casact#1208/casact#1211/casact#1212/casact#1213 would otherwise wipe documented indexers, shape attrs, or arithmetic dunders.

Co-authored-by: Cursor <cursoragent@cursor.com>
@henrydingliu

Copy link
Copy Markdown
Member

good with changes. please resolve conflict

Comment thread docs/_templates/autosummary/class_inherited.rst
Co-authored-by: Cursor <cursoragent@cursor.com>
@EKtheSage

Copy link
Copy Markdown
Contributor Author

Merged main (conflict was pyproject.toml after #1204). dunders.py already passes the CI ruff invocation that clears per-file ignores, including the new E2 rules.

CI pandas pads the development-age header with extra spaces; the cell values already matched.

Co-authored-by: Cursor <cursoragent@cursor.com>
@EKtheSage

Copy link
Copy Markdown
Contributor Author

Doctest miss was header padding on tri + 10 / * 2 / - 10 / /, not the arithmetic. Those outputs now use NORMALIZE_WHITESPACE.

henrydingliu pushed a commit that referenced this pull request Aug 14, 2026
* docs: add Triangle shape/empty/compute doctest examples (#704)

Co-authored-by: Cursor <cursoragent@cursor.com>

* Tighten TriangleBase examples from review on nan_triangle, get_array_module, and compute.

Print the nan mask as-is, show numpy/sparse module identity, and document compute with a dask code sample instead of a numpy no-op doctest.

Co-authored-by: Cursor <cursoragent@cursor.com>

* Fix E721 in TriangleBase, show a fake compute() output, and align the autosummary template.

The ruff workflow lints touched files with per-file ignores cleared. The template now unions the documented Triangle attrs and arithmetic dunders so #1208, #1212, and #1213 do not clobber each other on merge.

Co-authored-by: Cursor <cursoragent@cursor.com>

---------

Co-authored-by: Cursor <cursoragent@cursor.com>
@henrydingliu
henrydingliu merged commit db78185 into casact:main Aug 14, 2026
13 checks passed
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.

4 participants