Skip to content

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

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

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