Skip to content

[BUG] Triangle-to-Triangle comparison fails #1394

Description

@genedan

Are you on the latest chainladder version?

  • Yes, this bug occurs on the latest version.

Describe the bug in words

A comparison such as raa < raa fails.

How can the bug be reproduced?

import chainladder as cl
raa = cl.load_sample('raa')

raa < raa
Traceback (most recent call last):
 ... 
line 524, in __lt__
    obj.values = xp.nan_to_num(obj.values) < xp.nan_to_num(value)
                                             ~~~~~~~~~~~~~^^^^^^^
TypeError: no implementation found for 'numpy.nan_to_num' on types that implement __array_function__: [<class 'chainladder.core.triangle.Triangle'>]

What is the expected behavior?

This should behave like the numpy and Pandas analogues:

import numpy as np

a = np.array([[1.0, 2.0], [3.0, np.nan]])
b = np.array([[1.0, 1.0], [9.0, 9.0]])

print(a)
array([[ 1.,  2.],
       [ 3., nan]])

print(b)

array([[1., 1.],
       [9., 9.]])

a < b
# array([[False, False],
#        [ True, False]])      NaN compares False

a <= b
# array([[ True, False],
#        [ True, False]])      differs from < at the equal cell

a < np.array([[1.0, 2.0, 3.0]])
# ValueError: operands could not be broadcast together with shapes (2,2) (1,3)


import numpy as np
import pandas as pd

d1 = pd.DataFrame({"x": [1.0, 3.0], "y": [2.0, np.nan]}, index=["a", "b"])
d2 = pd.DataFrame({"x": [1.0, 9.0], "y": [1.0, 9.0]}, index=["a", "b"])

print(d1)
     x    y
a  1.0  2.0
b  3.0  NaN

print(d2)
     x    y
a  1.0  1.0
b  9.0  9.0

d1 < d2
#        x      y
# a  False  False
# b   True  False       NaN compares False

d1 <= d2
#       x      y
# a  True  False        differs from < at the equal cell
# b  True  False

d3 = pd.DataFrame({"x": [1.0, 9.0]}, index=["a", "b"])

d1 < d3
#       x   y
# a   2.0 NaN
# b  12.0 NaN

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

    Low

    Scope

    Codebase

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions