You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[FEAT] New Triangle constructor that starts with a Triangle #1466
is_cumulative is a core attribute of Triangle. it should become a property (see is_pattern for example) so we can add it to typing.py.
revised issue:
@Abhayindia brings up a very meritorious idea below. we religiously avoid constructing new triangles inside the codebase. most triangle creation involves keeping track of which existing triangle is the closest in attribute/property, making a copy of that triangle, then modifying various attributes/properties.
but a new triangle constructor method similar to this can introduce a lot of rigor to the codebase, something like
i asked various AI. they all seem to agree that a constructor method is a better idea than constantly replacing attributes. the benefits that resonated with me are
making the package look more intentional and mature.
making code more readable and succinct. take this snippet for example.
allow for the resulting triangle to validated, similar to how dunders are set up.
Happy to take this. One design point worth settling first: is_pattern is read-only and derived, but is_cumulative is intrinsic state, set from the constructor and persisted by io.py, and 20 places across development/, methods/ and adjustments/ assign to it.
So I would make it a property with a setter over a private _is_cumulative, which keeps those call sites working and still lets it into typing.py. Say the word if you would rather those 20 assignments were reworked instead.
@Abhayindia thanks for offering! what you described is what i had in mind. but im also curious if you think this is a sustainable pattern (no pun intended) for the package
Concretely yes, because it is already the shape in typing.py: index, columns and origin are each declared on TriangleProtocol as a property plus a setter overload, with is_val_tri getter-only. is_cumulative would be the fourth of that kind rather than a new precedent.
Where I would not generalise it: a setter that only writes a private field is ceremony unless it enforces something. The thing worth watching is the 20 assignment sites, most of which stamp the flag immediately after building a triangle, so the sustainable end state is fewer of those, probably a constructor argument, rather than a tidier wrapper around them. Happy to do the property now and note which sites look like they want to be constructor args.
that's an intriguing idea. a couple questions to make sure i understand
would this same concern about sustainability apply to all the places where we assign tri.value?
is this constructor somewhat similar to DevelopmentBase._param_property?
having this constructor means we would get rid of all these property setters, correct? is_pattern would be read-only. if i want to make a pattern triangle, i would need to go through the constructor
it would even mean that we dont need origin or development setters anymore?
Yes to the constructor idea: _param_property (development/base.py:366 and development.py:487) is already one in disguise, and 12 sites stamp is_pattern = True, so is_pattern (14 assignments) and is_cumulative (20) could become read-only. values is a bigger case (108 assignment sites, the payload rather than a flag), and the origin/development setters have real callers (core/pandas.py:1061-1063, two tests), so I would scope step one to the flags.
Two things the sketch misses: Triangle.copy() already exists (core/triangle.py:2153), so overloading it as written recurses through self.copy() (I ran it) and if values: raises on arrays (use is not None), so a separate method name avoids both.
The sequence to own is longer than values plus flags: _param_property also resets virtual_columns and relies on _set_slicers() (39 call sites), and validating shapes only works if values and ddims arrive in one call, since development.py:487 sets values before ddims.
These ideas come from functional programming. At the risk of oversimplifying an entire paradigm by summarizing it into a single sentence, I'd say we should try to minimize inplace mutation and side effects. This is just an ideal though, which numpy and pandas don't adhere to (plenty of inplace examples for instance), but I think we should apply the ideas when they can reduce bugs.
I'm already finding in our recent work that repeated calls to _set_slicers() (see #1389 and #1303) are pretty annoying and if you're finding that other properties need to be manually reset when modifying triangles, there is a strong justification for generalization.
Some things to think about would be:
Making sure performance doesn't degrade after implementing the new constructor
Maybe start with a private method first - I think this might take multiple PRs to accomplish and for the API to mature before promoting it to a public method.
The last 3 calls in the sketch mutate self, so we may have to rework those
since we are conceptually aligned on a potential need, would it make sense to actually just start in #1304? i.e. a private method that replaces values, origin, and development
For that PR, you'll see _set_odims and _set_ddims move to _set_origin and _set_development in axis.py. It's already a lot to review, so I think further refactorings into a more elegant/unified method would have to wait to #1454 at the earliest. I think working on the values would have to go in its own PR.
i think we are talking about different things. _set_odims and _set_ddims are initialization helpers, not triangle manipulation.
the intent is also to help break #1304 into smaller chunks. it really doesn't have to be as massive as it is currently.
PR 1: create a private triangle modification method that only copies a triangle and modifies development
PR 2-5: go through a quarter of the codebase at a time, move all ddims assignments to new method
PR 6: add origin modification to this method
PR 7-10: go through a quarter of the codebase at a time, move all odims assignments to new method
So you mean you want to replace a section like this with the new method?
I'd rather get the ddims/odims deprecation done first, since we've already merged in the kdims/vdims deprecation and I can use my mental model of how I reviewed the first half for the second.
main currently has a Frankenstein mix of ddims/odims/development/origin/index/columns and a half finished TriangleAxis class. Getting the existing stack in will allow you to work with a clean set of dimensions and more mature TriangleAxis class.
So you mean you want to replace a section like this with the new method?
yes
I'd rather get the ddims/odims deprecation done first
my sense is that the #1304 is about 25% of the way done. #1303 began the _axes pattern. but #1304 is still all on _ddims and _odims. the sunk cost is small compared to the future state you are headed. if that assessment is not accurate and you believe #1304 is close, then of course closing it out via its current path should take precedence.
my sense is that the #1304 is about 25% of the way done. #1303 began the _axes pattern. but #1304 is still all on _ddims and _odims.
Fair point that #1304 is a massive diff. Touching origin and development across the whole package inevitably reaches a lot of call sites.
The TriangleAxis descriptors for origin and development are actually already built and tested, they were just sitting on the next branch (#1454).. Folding those descriptors directly into #1304 brings origin and development onto TriangleAxis alongside index and columns, completing the 4-axis model without leaving main in an intermediate state.
would it make sense to actually just start in #1304? i.e. a private method that replaces values, origin, and development
A modify constructor is a neat idea and would definitely help clean up all the in-place values mutations across the repo. Doing that right after #1304 lands feels like the cleanest sequence, once the axis descriptors are settled. Open to thoughts on that sequencing.
Activity
Abhayindia commentedon Oct 17, 2026
Happy to take this. One design point worth settling first:
is_patternis read-only and derived, butis_cumulativeis intrinsic state, set from the constructor and persisted byio.py, and 20 places acrossdevelopment/,methods/andadjustments/assign to it.So I would make it a property with a setter over a private
_is_cumulative, which keeps those call sites working and still lets it intotyping.py. Say the word if you would rather those 20 assignments were reworked instead.henrydingliu commentedon Oct 17, 2026
@Abhayindia thanks for offering! what you described is what i had in mind. but im also curious if you think this is a sustainable pattern (no pun intended) for the package
Abhayindia commentedon Oct 17, 2026
Concretely yes, because it is already the shape in
typing.py:index,columnsandoriginare each declared onTriangleProtocolas a property plus a setter overload, withis_val_trigetter-only.is_cumulativewould be the fourth of that kind rather than a new precedent.Where I would not generalise it: a setter that only writes a private field is ceremony unless it enforces something. The thing worth watching is the 20 assignment sites, most of which stamp the flag immediately after building a triangle, so the sustainable end state is fewer of those, probably a constructor argument, rather than a tidier wrapper around them. Happy to do the property now and note which sites look like they want to be constructor args.
henrydingliu commentedon Oct 17, 2026
that's an intriguing idea. a couple questions to make sure i understand
DevelopmentBase._param_property?is_patternwould be read-only. if i want to make a pattern triangle, i would need to go through the constructorAbhayindia commentedon Oct 19, 2026
Yes to the constructor idea:
_param_property(development/base.py:366 and development.py:487) is already one in disguise, and 12 sites stampis_pattern = True, sois_pattern(14 assignments) andis_cumulative(20) could become read-only.valuesis a bigger case (108 assignment sites, the payload rather than a flag), and theorigin/developmentsetters have real callers (core/pandas.py:1061-1063, two tests), so I would scope step one to the flags.[-][CHORE] turn is_cumulative into property[/-][+][FEAT] New Triangle constructor that starts with a Triangle[/+]henrydingliu commentedon Oct 19, 2026
@casact/chainladder-maintainers curious to get your take
@Abhayindia please read over my revised issue description and let me know what I missed.
Abhayindia commentedon Oct 19, 2026
Two things the sketch misses:
Triangle.copy()already exists (core/triangle.py:2153), so overloading it as written recurses throughself.copy()(I ran it) andif values:raises on arrays (useis not None), so a separate method name avoids both.The sequence to own is longer than values plus flags:
_param_propertyalso resetsvirtual_columnsand relies on_set_slicers()(39 call sites), and validating shapes only works if values and ddims arrive in one call, since development.py:487 sets values before ddims.henrydingliu commentedon Oct 19, 2026
@Abhayindia thanks! revised.
genedan commentedon Oct 19, 2026
These ideas come from functional programming. At the risk of oversimplifying an entire paradigm by summarizing it into a single sentence, I'd say we should try to minimize inplace mutation and side effects. This is just an ideal though, which numpy and pandas don't adhere to (plenty of
inplaceexamples for instance), but I think we should apply the ideas when they can reduce bugs.I'm already finding in our recent work that repeated calls to
_set_slicers()(see #1389 and #1303) are pretty annoying and if you're finding that other properties need to be manually reset when modifying triangles, there is a strong justification for generalization.Some things to think about would be:
henrydingliu commentedon Oct 19, 2026
since we are conceptually aligned on a potential need, would it make sense to actually just start in #1304? i.e. a private method that replaces
values,origin, anddevelopmentgenedan commentedon Oct 19, 2026
For that PR, you'll see
_set_odimsand_set_ddimsmove to_set_originand_set_developmentinaxis.py. It's already a lot to review, so I think further refactorings into a more elegant/unified method would have to wait to #1454 at the earliest. I think working on thevalueswould have to go in its own PR.henrydingliu commentedon Oct 19, 2026
i think we are talking about different things.
_set_odimsand_set_ddimsare initialization helpers, not triangle manipulation.the intent is also to help break #1304 into smaller chunks. it really doesn't have to be as massive as it is currently.
PR 1: create a private triangle modification method that only copies a triangle and modifies development
PR 2-5: go through a quarter of the codebase at a time, move all ddims assignments to new method
PR 6: add origin modification to this method
PR 7-10: go through a quarter of the codebase at a time, move all odims assignments to new method
genedan commentedon Oct 19, 2026
So you mean you want to replace a section like this with the new method?
I'd rather get the ddims/odims deprecation done first, since we've already merged in the kdims/vdims deprecation and I can use my mental model of how I reviewed the first half for the second.
maincurrently has a Frankenstein mix of ddims/odims/development/origin/index/columns and a half finished TriangleAxis class. Getting the existing stack in will allow you to work with a clean set of dimensions and more mature TriangleAxis class.henrydingliu commentedon Oct 19, 2026
yes
my sense is that the #1304 is about 25% of the way done. #1303 began the
_axespattern. but #1304 is still all on _ddims and _odims. the sunk cost is small compared to the future state you are headed. if that assessment is not accurate and you believe #1304 is close, then of course closing it out via its current path should take precedence.priyam0k commentedon Oct 20, 2026
Fair point that #1304 is a massive diff. Touching origin and development across the whole package inevitably reaches a lot of call sites.
The TriangleAxis descriptors for origin and development are actually already built and tested, they were just sitting on the next branch (#1454).. Folding those descriptors directly into #1304 brings origin and development onto TriangleAxis alongside index and columns, completing the 4-axis model without leaving main in an intermediate state.
A modify constructor is a neat idea and would definitely help clean up all the in-place values mutations across the repo. Doing that right after #1304 lands feels like the cleanest sequence, once the axis descriptors are settled. Open to thoughts on that sequencing.