Repository navigation
[TST] Use Triangle.equals in tests and docs - #1539
Conversation
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).
Pyright Type CompletenessView the full Project (full
Other symbols referenced but not exported by
Symbols without documentation:
Patch (exported symbols added or changed by this PR): no exported symbol type-completeness changes detected. |
Codecov Report✅ All modified and coverable lines are covered by tests. 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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).
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).
|
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).
|
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.) |
Summary of Changes
Since #1535,
==and!=between two triangles emit aFutureWarning(#1395). This PR moves the repository's own uses over toTriangle.equals, as henrydingliu asked in #1395:a == bbecomesa.equals(b), anda != b(15 of them) becomesnot a.equals(b).execute_notebooks: forceindocs/_config.yml).Triangle.to_pickleandTriangle.to_json(chainladder/core/io.py), which the Doctest job runs.The two tests in
test_arithmetic.pythat check the deprecation itself,test_eq_non_triangleandtest_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 Pythonboolsince #1535 andequalsdoes too, so a re-run of those notebooks showsTrue, 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 oftest_triangle_from_dataframe_interchange_protocol, which skips here without polars; I changed it by hand. With the versions inuv.lock(polars 1.34.0, pyarrow 25.0.0) that test passes on this branch under-W error::FutureWarning, and onmainit fails under the same flag, raising theFutureWarningfrom itsassert 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 intotest_io.py; the moved tests still compare triangles with==.Tests
mainin this environment: 2test_heatmap_rendercases need IPython, which isn't installed here, and 6test_development.pycases that turn warnings into errors trip on numpy 2.5'sDeprecationWarningabout the generic timedelta unit.==FutureWarnings. Onmainit records 379, from 186 lines in 13 test files.sphinx -b doctest(Sphinx 7.4.7 and numpydoc 1.9.0, theuv.lockversions): both pass on this branch with the==FutureWarningturned into an error, and both fail onmainunder the same filter.==warnings on this branch. Onmainthe same job lists 187 sites: the 186 lines above and the last assert of the interchange test.ruff checkandruff format --checkare clean, and the Ruff workflow's import-sorting command finds nothing to sort in the changed files.Submitter's Checklist
[FIX],[FEAT],[DOCS],[TST],[CHORE], or[BRK]).Reviewer's Checklist