Skip to content

[BUG] dev_to_val and val_to_dev does not respect inplace - #1480

Open
henrydingliu wants to merge 14 commits into
casact:mainfrom
henrydingliu:bug/dev_val_inplace
Open

henrydingliu wants to merge 14 commits into
casact:mainfrom
henrydingliu:bug/dev_val_inplace

Conversation

@henrydingliu

@henrydingliu henrydingliu commented Oct 10, 2026 •

Copy link
Copy Markdown
Member

Summary of Changes

  • changed _auto_sparse to return None
  • changed _val_dev to mutate inplace only
  • _val_dev, grain, dev_to_val, val_to_dev now preserve backend
  • dev_to_val, val_to_dev now respect inplace

Related GitHub Issue(s)

closes #1477
closes #1482

AI/LLM Usage

None

Additional Context for Reviewers

  • _auto_sparse is a private method that already mutates inplace. returning the object is redundant
  • cleaning up _auto_sparse was at one point relevant to the core issue of the PR. I've since removed _auto_sparse from _val_dev to address a long-standing bug where dev_to_val inadvertently changes a sparse triangle back to numpy
  • _val_dev is a private helper method used in dev_to_val and val_to_dev. with the refactor of these two public methods, there is no longer a need for _val_dev to have inplace=False.

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).

Note

Medium Risk
Changes behavior of widely used development/valuation conversion methods and inplace return values; incorrect backend restoration could affect sparse vs numpy performance or memory for large triangles.

Overview
Fixes dev_to_val and val_to_dev so inplace=True mutates the triangle and returns None, while inplace=False returns a new Triangle (copy-then-mutate). Docstrings now document Triangle | None return types.

The private _val_dev helper is in-place only: it temporarily switches to sparse for the coordinate reshape, then set_backend restores the caller’s original backend instead of routing through _auto_sparse (which could flip sparse triangles back to numpy during conversion).

_auto_sparse is aligned with its existing mutation behavior by returning None; aggregation paths in pandas.py and triangle construction call it without reassigning self.

Tests are updated for inplace semantics, _auto_sparse expectations, grain assertions via to_frame(), and a new test_dev_val_inplace.

Reviewed by Cursor Bugbot for commit 3279003. Bugbot is set up for automated code reviews on this repo. Configure here.

@github-actions

github-actions Bot commented Oct 10, 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.7% of exported symbols fully typed (229 / 1457)

Known Ambiguous Unknown Total
Project (head) 229 108 1120 1457

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

Patch (exported symbols added or changed by this PR): 66.7% fully typed (2 / 3)

Known Ambiguous Unknown Total
Patch 2 0 1 3
Patch symbol details
Symbol Status Change
chainladder.core.tests.test_triangle.test_dev_val_inplace ❌ unknown new
chainladder.core.triangle.Triangle.dev_to_val ✅ known changed (was ❌ unknown)
chainladder.core.triangle.Triangle.val_to_dev ✅ known changed (was ❌ unknown)

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

Comment thread chainladder/core/triangle.py

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

Comment thread chainladder/core/triangle.py Outdated
Comment thread chainladder/core/tests/test_triangle.py Outdated
Comment thread chainladder/core/tests/test_triangle.py

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

Comment thread chainladder/core/triangle.py

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

Comment thread chainladder/core/triangle.py

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

Comment thread chainladder/core/triangle.py Outdated

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 76cf401. Configure here.

Comment thread chainladder/core/triangle.py Outdated
@codecov

codecov Bot commented Oct 11, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.18%. Comparing base (856f87b) to head (3279003).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1480      +/-   ##
==========================================
+ Coverage   94.15%   94.18%   +0.03%     
==========================================
  Files          96       96              
  Lines        5852     5851       -1     
  Branches      739      734       -5     
==========================================
+ Hits         5510     5511       +1     
+ Misses        221      220       -1     
+ Partials      121      120       -1     
Flag Coverage Δ
unittests 94.18% <100.00%> (+0.03%) ⬆️

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.

@henrydingliu
henrydingliu marked this pull request as ready for review October 11, 2026 04:16
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.

[BUG] dev_to_val change sparse triangle to numpy [BUG] dev_to_val, val_to_dev, and _val_dev inplace argument not working

1 participant