Skip to content

[BUG] Use __eq__ and .equals() to distinguish between elementwise and whole-object comparison #1395

Open

Description

@genedan

Are you on the latest chainladder version?

  • Yes, this bug occurs on the latest version.

Describe the bug in words

Consider the following example:

import pandas as pd

df1 = pd.DataFrame({'a': [1, 2], 'b': [4, 5]})
df2 = pd.DataFrame({'a': [1, 3], 'b': [7, 5]})

df1 == df2

       a      b
0   True  False
1  False   True

df1.equals(df2)

True

The == operator does elementwise comparison, returning an array of bools. The .equals method compares the whole object, returning a boolean scalar.

How can the bug be reproduced?

Chainladder does not have elementwise comparison, and the == acts as whole-object comparison

import chainladder as cl

raa = cl.load_sample('raa')

raa == raa

True

raa.equals(raa)

Traceback (most recent call last):
    ~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<ipython-input-36-a11e75dbc397>", line 1, in <module>
    raa.equals(raa)
    ^^^^^^^^^^
AttributeError: 'Triangle' object has no attribute 'equals'

What is the expected behavior?

== should do elementwise comparison. The .equals() method should be defined to do whole-object comparison, replacing the current functionality of ==.

Would you be willing to contribute this ticket?

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

Activity

  1. added this to the v0.11.0 milestone on Sep 18, 2026
  2. added
    Great First Contribution! 🌱Beginner friendly tickets with narrow scope and huge impact. Perfect to get your feet wet!
    on Sep 18, 2026
  3. updated Scope Codebase and Effort Medium on Sep 18, 2026
  4. added theissue type on Sep 18, 2026
  5. moved this from Not Ready to Ready in Chainladder-Python Project Boardon Sep 20, 2026
  6. henrydingliu commented on Sep 24, 2026

    @henrydingliu
    Member

    Is this {BUG] or [BRK]? can we do anything more than a deprecation warning?

  7. genedan commented on Sep 24, 2026

    @genedan
    MemberAuthor

    I'd classify it as a bug since == shouldn't have been returning a scalar in the first place. According to PDEP-17, breaking changes caused by bugs don't need a warning.

  8. henrydingliu commented on Sep 25, 2026

    @henrydingliu
    Member

    it's true that we never documented dunders till recently. but we have so many assert tri1 == tr2 in the test suite that users would have reasonably relied upon to be the intended behavior. "another package does it differently" is only circumstantial whereas "this package has been doing it this way since the beginning" is direct.

    we can do a quicker deprecation cycle, i.e. introduce equals in 0.11.0, change == in 1.0.0?

  9. genedan commented on Sep 29, 2026

    @genedan
    MemberAuthor

    We could give it some time. A last concern for me though would be the kind of warning message we should issue in the meantime. How about we do something like:

    1. Implement .equals() right away
    2. Warn people that == will no longer be used for whole object comparison and to use .equals() instead.
  10. henrydingliu commented on Nov 5, 2026

    @henrydingliu
    Member

    @scks1 thanks for getting this going! now there's just the massive follow-up task of replacing all tri == other_tri in the codebase. interested in taking that on?

  11. scks1 commented on Nov 5, 2026

    @scks1
    Contributor

    Yes, happy to. #1539 moves them to equals: 187 comparisons in 13 test files and 15 in 7 docs notebooks. The library code itself has none.

    (This reply was made with Árbol, an AI assistant, under my direction.)

  12. henrydingliu commented on Nov 10, 2026

    @henrydingliu
    Member

    all available work for 0.11 is done. moving milestone to 1.0 for element-wise ==

  13. modified the milestones: v0.11.0, v1.0.0 on Nov 10, 2026
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

    Great First Contribution! 🌱Beginner friendly tickets with narrow scope and huge impact. Perfect to get your feet wet!

    Type

    Fields

    Priority

    High

    Effort

    Medium

    Scope

    Codebase

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions