Skip to content

[BRK] Methods with inplace parameter should return None instead of Self #1266

Open
0 of 2 issues completed
Open

Description

@genedan

Description

Triangle methods that have an inplace parameter tend to return Self, such as:

def set_index(self, value, inplace=False):
"""Sets the index of the Triangle"""
if inplace:
self.index = value
return self
else:
new_obj = self.copy()
return new_obj.set_index(value=value, inplace=True)

This is inconsistent with Pandas behavior, where such methods mutate the object in-place and return None.

For example, see the docs page on DataFrame.sort_values().

Changing the return value to None would also align with the behavior of built-in Python methods, such as list.sort(). See this discussion from Guido from way back in the day.

His justification for the practice is that it enhances readability and lets the user know what object chained methods are acting upon.

Is your feature request aligned with the scope of the package?

  • Yes, absolutely!
  • No, but it's still worth discussing.
  • N/A (this request is not a codebase enhancement).

Describe the solution you'd like, or your current workaround.

methods with related bugs that require additional fix

Deprecation warning already done for these methods, behavior change will occur in 2.0:

  • TrianglePandas.astype()
  • Common.set_backend()
  • Triangle.set_index()
  • Triangle.incr_to_cum()
  • Triangle.grain()
  • TrianlgePandas.fillna()
  • TrianglePandas.fillzero()

We should first:

1. Issue a warning for the 0.11.0 release that the return value for these methods will change to None.
2. After the 0.11.0, update the methods to return None.

Do you have any additional supporting notes?

See related discussion.

Would you be willing to contribute this ticket?

  • Yes, absolutely!
  • Yes, but I would like some help.
  • No.

Activity

  1. added this to the v1.0.0 milestone on Sep 2, 2026
  2. updated Effort Medium and Priority High on Sep 2, 2026
  3. added theissue type on Sep 2, 2026
  4. henrydingliu commented on Sep 4, 2026

    @henrydingliu
    Member

    I'd like to push all breaking changes past 1.0.0.

  5. genedan commented on Sep 4, 2026

    @genedan
    MemberAuthor

    Should this one be scheduled for 2.0.0 then?

  6. henrydingliu commented on Sep 4, 2026

    @henrydingliu
    Member

    yes please. we can put in a deprecation warning right now though.

  7. modified the milestones: v1.0.0, v2.0.0 on Sep 4, 2026
  8. henrydingliu commented on Oct 3, 2026

    @henrydingliu
    Member

    @genedan @priyam0k @kennethshsu we punted on the removal timeline in #1409. before i start working on the deprecation tag for the rest of these, can we please align on a removal timeline? i'm open to anything between 1.1 and 2.0

  9. genedan commented on Oct 3, 2026

    @genedan
    MemberAuthor

    I'm still confused as to why a lot of the breaking changes we identified prior to 1.0.0 aren't scheduled for it. Isn't the major version bump an opportunity to have them done then? And then the breaking changes identified after 1.0.0 get implemented in 2.0.0?

  10. henrydingliu commented on Oct 3, 2026

    @henrydingliu
    Member

    I'm still confused as to why a lot of the breaking changes we identified prior to 1.0.0 aren't scheduled for it. Isn't the major version bump an opportunity to have them done then? And then the breaking changes identified after 1.0.0 get implemented in 2.0.0?

    because we are close to 1.0.

    but i suppose "when/what is 1.0" is still an open question.

  11. genedan commented on Oct 4, 2026

    @genedan
    MemberAuthor

    For this particular ticket, 2.0.0 then, that would be consistent with semver.

  12. priyam0k commented on Oct 4, 2026

    @priyam0k
    Contributor

    before i start working on the deprecation tag for the rest of these, can we please align on a removal timeline? i'm open to anything between 1.1 and 2.0

    Targeting 2.0 for the actual removal and return value switch aligns directly with semver, since altering inplace return semantics from Self to None or dropping parameters breaks existing chained calls. Issuing the FutureWarnings now in 1.0 gives users a clean migration window without introducing breaking behavior in minor 1.x releases.

  13. henrydingliu commented on Oct 4, 2026

    @henrydingliu
    Member

    I have a working decorator for this deprecation in #1468. but there's a big problem. we don't have a way to turn off the warning if the user is correctly not assigning .inplace(True) to anything. it will warn every time someone calls inplace=True. even if we factor all of it out of the codebase, it can still be annoying to users.

    do you want to live with the annoyance or just stick a deprecation warning in the docstring?

  14. genedan commented on Oct 4, 2026

    @genedan
    MemberAuthor

    I think this one of the reasons why Pandas (and maybe other libraries) don't do the deprecation when fixing bugs. Sometimes you can't tell if someone was trying to use a feature the right way or the wrong way and the warning would be annoying to a user who was using it the right way. I think we run into the same problem with #1395.

    Docstring warning is fine with me. I'm also okay with just fixing this one on the spot.

  15. henrydingliu commented on Oct 5, 2026

    @henrydingliu
    Member

    i had to re-familiarize myself with pandas' breaking changes around astype(str) on NaN. It looks like Pandas announced the intention via a PDEP in 2024, put out a migration guide in 2025, then actually changed the code in pandas 3 in 2026. i think this is a reasonable approach that we can learn from.

    I know we've talked about a CDEP before. Honestly I'm not sure how many people would read it (I certainly don't read PDEPs even though I use pandas daily). I do think a highly visible migration guide ahead of 1.0 would do a lot of good. so it's up on #1472. with this increased visibility, i think we can afford to accelerate some of the deprecations.

    Sometimes you can't tell if someone was trying to use a feature the right way

    i like this framing. what breaks this package when someone assumes that it works the same as pandas?

    • astype breaks since it defaults to inplace=true (supplied object is mutated)
    • tri == other breaks since it returns a single bool

    the other two (inplace=True returns mutated object and passing slice into at) doesn't break if user just follows existing pandas behavior.

    does it work for you if we accelerate the first two but still punt on the other two? the idea is that by 1.0, pandas behavior will work in this package (along with some non-pandasian behavior).

  16. genedan commented on Oct 8, 2026

    @genedan
    MemberAuthor

    I don't think users would need to read PDEP or CDEP, but once contributors wind up in our shoes they might. I didn't read them either until I got pretty deep into package writing (this year).

    does it work for you if we accelerate the first two but still punt on the other two? the idea is that by 1.0,

    Works for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Fields

    Priority

    High

    Effort

    Medium

    Scope

    Codebase

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions