Skip to content

docs: add Triangle shape/empty/compute examples (#704) - #1211

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

docs: add Triangle shape/empty/compute examples (#704)#1211
henrydingliu merged 4 commits into
casact:mainfrom
EKtheSage:docs/704-base-examples

Conversation

@EKtheSage

Copy link
Copy Markdown
Contributor

Summary of Changes

  • Add doctest Examples for Triangle.shape, .empty, .dimensionality, .nan_triangle, .compute, and .get_array_module in chainladder/core/base.py.
  • Stop excluding those attributes from the inherited-class autosummary template so the examples appear on the Triangle API page.

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 (3d19814).

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

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.

Comment thread chainladder/core/base.py Outdated

Examples
--------
Numpy-backed Triangles are already materialized, so ``compute``

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.

not sure how useful this is. i would recommend using code-block to imitate realistic numba usage.

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.

compute() is the dask materialize path, not numba. The numpy identity doctest did not show that, so it is now a code-block of set_backend('dask') then compute(). Dask is optional and the dask backend is deprecated, which is why that sample is not a doctest.

Comment thread chainladder/core/base.py Outdated
.. testcode::

raa = cl.load_sample('raa')
print(raa.get_array_module().__name__)

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.

an example using np and sp would be more instructive

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.

Updated to compare against np and sp with is, so it is clear get_array_module() returns those module objects.

Comment thread chainladder/core/base.py Outdated
.. testcode::

import numpy as np
mask = np.isnan(cl.load_sample('raa').nan_triangle[-1])

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.

just calling nan_triangle and printing it would be sufficient. no need for further manipulation.

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.

Dropped the boolean mask. The example now prints nan_triangle directly.

…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>
Comment thread chainladder/core/base.py Outdated
.. code-block:: python

tri = cl.load_sample('raa').set_backend('dask')
tri = tri.compute()

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.

can you fake the output also?

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.

Added a pycon sample that shows tri.array_backend as 'numpy' after compute().


.. currentmodule:: {{ module }}

{% set documented_attrs = ['shape', 'empty', 'dimensionality', 'nan_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.

are the changes to this template compatible with #1212 and #1213?

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.

They were not: last merge would overwrite the file. #1211, #1212, #1213, and #1208 now share the same union: un-exclude loc/iloc/at/iat plus shape/empty/dimensionality/nan_triangle, and special-members for the arithmetic dunders. cdf_/ibnr_/pct_reported_ stay excluded on Triangle.

@henrydingliu

Copy link
Copy Markdown
Member

lastly, could you please take care of the ruff violation?

… 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

Ruff: replaced type(...) == with isinstance in TriangleBase and dropped the base.py E721 ignore.

compute() now has a pycon sample with a fake 'numpy' output.

The autosummary template is aligned with #1208/#1212/#1213 so the last merge does not wipe documented attrs or 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>
isinstance() sent the dask stand-in down the pandas path and skipped the deprecation warning. E2 on base.py is fixed; the remaining type() compare is noqa'd because CI clears per-file ignores.

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

Copy link
Copy Markdown
Contributor Author

Merged main (conflict was pyproject.toml after #1204).

The earlier E721 swap to isinstance(data, pd.DataFrame) was wrong here: _FakeDaskFrame is a DataFrame subclass, so that check skipped the dask DeprecationWarning and failed test_triangle_dask_input_deprecated on every Python version. Restored type(data) != pd.DataFrame with an inline # noqa: E721 because CI clears per-file ignores. The pd.Period isinstance change stays.

E2 on base.py is fixed and the file ignore is dropped.

@henrydingliu
henrydingliu merged commit 5da0654 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.

2 participants