Skip to content

[TST] Use Triangle.equals in tests and docs - #1539

Merged
henrydingliu merged 6 commits into
casact:mainfrom
scks1:tst-triangle-equals-in-tests
Nov 5, 2026
Merged

henrydingliu merged 6 commits into
casact:mainfrom
scks1:tst-triangle-equals-in-tests

Conversation

@scks1

@scks1 scks1 commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Summary of Changes

Since #1535, == and != between two triangles emit a FutureWarning (#1395). This PR moves the repository's own uses over to Triangle.equals, as henrydingliu asked in #1395:

  • 187 comparisons in 13 test files. a == b becomes a.equals(b), and a != b (15 of them) becomes not a.equals(b).
  • 15 comparisons in 7 docs notebooks, which run on every docs build (execute_notebooks: force in docs/_config.yml).
  • 2 comparisons in the docstring examples of Triangle.to_pickle and Triangle.to_json (chainladder/core/io.py), which the Doctest job runs.

The two tests in test_arithmetic.py that check the deprecation itself, test_eq_non_triangle and test_eq_and_ne_warn_and_match_equals, still use ==.

Apart from those two docstring examples, the library code has no triangle ==. A full test run with the warning traced to its source found none, and neither did a scan of the non-test modules. That scan read code but not docstrings, so my first push missed the two examples. The Doctest job's log showed both still warning.

Six of the edited notebook cells stored np.True_ as their output. == has returned a Python bool since #1535 and equals does too, so a re-run of those notebooks shows True, and the stored outputs now say so. No other outputs or execution counts changed.

The second commit sorts imports in 12 of the 13 changed test files, the fifth does the same for core/io.py, and the sixth sorts the 8 import cells in the edited notebooks, as the Ruff workflow suggests for changed files. The notebook commit only reorders imports and adds blank lines between import groups.

Related GitHub Issue(s)

Part of #1395, following #1535. Parent issue: #1396.

AI/LLM Usage

This change was written with Árbol, an AI assistant running on Muse, working under my direction. It wrote the code changes, ran the checks listed below, and drafted this description. I reviewed the diff and the results before submitting.

Additional Context for Reviewers

How the comparisons were found. A pytest plugin wrapped TriangleDunders.__eq__ and recorded the source span of every call, one test file at a time, and a script rewrote each recorded span that was a single == or != between two triangles. A second recorded run with the rewrite in place found == only in the two deprecation tests and executed every rewritten line except one. That line is the last assert of test_triangle_from_dataframe_interchange_protocol, which skips here without polars; I changed it by hand. With the versions in uv.lock (polars 1.34.0, pyarrow 25.0.0) that test passes on this branch under -W error::FutureWarning, and on main it fails under the same flag, raising the FutureWarning from its assert tri == expected. The notebooks went through the same recording, executed cell by cell; no other notebook compares two triangles.

Overlap with open PRs. This merges cleanly with #1304. It conflicts with #1465 in test_utilities.py, because #1465 moves the pickle tests that this PR edits into test_io.py; the moved tests still compare triangles with ==.

Tests

  • Full suite (Python 3.12.15, numpy 2.5.4, pandas 3.1.0): 1,426 passed, 2 skipped, 8 failed. The same 8 fail on main in this environment: 2 test_heatmap_render cases need IPython, which isn't installed here, and 6 test_development.py cases that turn warnings into errors trip on numpy 2.5's DeprecationWarning about the generic timedelta unit.
  • With warnings enabled, the same run records no == FutureWarnings. On main it records 379, from 186 lines in 13 test files.
  • The two docstring examples, run with sphinx -b doctest (Sphinx 7.4.7 and numpydoc 1.9.0, the uv.lock versions): both pass on this branch with the == FutureWarning turned into an error, and both fail on main under the same filter.
  • In CI on the first push, the 3.12 job's warnings summary listed no == warnings on this branch. On main the same job lists 187 sites: the 186 lines above and the last assert of the interchange test.
  • ruff check and ruff format --check are clean, and the Ruff workflow's import-sorting command finds nothing to sort in the changed files.

Submitter's Checklist

  • I have reviewed and am adhering to the standards outlined in the project Governing Doc.
  • The PR subject title summarizes the changes, with one proper prefix ([FIX], [FEAT], [DOCS], [TST], [CHORE], or [BRK]).
  • I am a human (not a bot), and this PR form is written by a human.

Reviewer's Checklist

  • The implementation addresses the associated issue(s).
  • The implementation is appropriate, maintainable, and follows ARCHITECTURE.md.
  • PR subject title has the proper prefix and the subject is appropriate.
  • Relevant issue(s) are linked.
  • AI/LLM usage is disclosed and appropriate.
  • Documentation and tests are appropriate.
  • CI tests passed, or any failures are acceptable.
  • Leave a comment with the final recommendation (e.g. approve as is, request a secondary review, or flag an area for more review).

scks1 added 3 commits November 5, 2026 05:59
Replace whole-triangle comparisons in the test suite, tri == other and
tri != other, with tri.equals(other) and not tri.equals(other). Since
the == deprecation each of these comparisons emits a FutureWarning.
The tests in test_arithmetic.py that check the deprecation itself keep
using ==.

Part of casact#1395.

Developed with an AI assistant (Árbol, running Muse).
Apply ruff's import sorting (rule I) to the test files changed in the
previous commit, as the Ruff workflow suggests for changed files.

Developed with an AI assistant (Árbol, running Muse).
Replace the whole-triangle == comparisons in the tutorial and user
guide notebooks with Triangle.equals. The docs build executes every
notebook, so these comparisons warn there. Six of the edited cells
stored np.True_ as their output; re-running them gives True, the
Python bool that equals returns, and the stored outputs now match.

Part of casact#1395.

Developed with an AI assistant (Árbol, running Muse).
@github-actions

github-actions Bot commented Nov 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): 16.1% of exported symbols fully typed (258 / 1600)

Known Ambiguous Unknown Total
Project (head) 258 106 1236 1600

Other symbols referenced but not exported by chainladder: 24

Known Ambiguous Unknown Total
Other (head) 11 1 12 24

Symbols without documentation:

  • Functions without docstring: 342
  • 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 Nov 5, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.38%. Comparing base (72f391f) to head (5e7e894).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1539   +/-   ##
=======================================
  Coverage   94.38%   94.38%           
=======================================
  Files          98       98           
  Lines        6219     6219           
  Branches      799      799           
=======================================
  Hits         5870     5870           
  Misses        225      225           
  Partials      124      124           
Flag Coverage Δ
unittests 94.38% <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.

The to_pickle and to_json docstrings each compare the restored
triangle with the original using ==, in a testcode block that the
Doctest job runs, so both emit the FutureWarning on every docs
build. Both now call equals. The expected output stays True, since
equals returns a Python bool.

Part of casact#1395.

Developed with an AI assistant (Árbol, running Muse).
@scks1 scks1 changed the title [TST] Use Triangle.equals in tests and docs notebooks [TST] Use Triangle.equals in tests and docs Nov 5, 2026
Apply ruff's import sorting (rule I) to io.py, which the previous
commit changed, as the Ruff workflow suggests for changed files.

Developed with an AI assistant (Árbol, running Muse).
@henrydingliu

Copy link
Copy Markdown
Member

thanks for the super fast turnaround on this! everything looks good. do you mind taking care of the handful of import ordering in notebooks (see ruff log)?

Apply ruff's import sorting (rule I) to the import cells of the seven
docs notebooks this PR changes, as the Ruff workflow suggests for
changed files. Each cell keeps its statements; only the order of the
imports and the blank lines between import groups change.

Developed with an AI assistant (Árbol, running Muse).
@scks1

scks1 commented Nov 5, 2026

Copy link
Copy Markdown
Contributor Author

Not at all. Done in 5e7e894: it sorts the 8 notebook import cells the Ruff step flagged, so Ruff's import check now passes on all the files this PR changes. Only the order of the imports and the blank lines between import groups change. I've updated the description to match.

(The commit and this reply were made with Árbol, an AI assistant, under my direction.)

@henrydingliu
henrydingliu merged commit 4283841 into casact:main Nov 5, 2026
11 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