Repository navigation
Labels
Great First Contribution! 🌱Beginner friendly tickets with narrow scope and huge impact. Perfect to get your feet wet!Beginner friendly tickets with narrow scope and huge impact. Perfect to get your feet wet!
Milestone
Description
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 NaNWould you be willing to contribute this ticket?
- Yes, absolutely!
- Yes, but I would like some help.
- No.
Metadata
Metadata
Assignees
Labels
Great First Contribution! 🌱Beginner friendly tickets with narrow scope and huge impact. Perfect to get your feet wet!Beginner friendly tickets with narrow scope and huge impact. Perfect to get your feet wet!
Type
Fields
Priority
High
Effort
Low
Scope
Codebase
Projects
- StatusShow more project fieldsDone
Activity
[-][BUG] Triangle-to-Triangle comparison failes[/-][+][BUG] Triangle-to-Triangle comparison fails[/+]henrydingliu commentedon Sep 20, 2026
@genedan I believe you are giving conflicting expected behavior between this issue and #1392. In this issue, NaN should always compare to false. In #1392, NaN is treated as 0, and can compare to True. Please let me know if I'm understanding these issues as you intend
@Abhayindia FYI
Abhayindia commentedon Sep 21, 2026
@henrydingliu you're reading them the same way I am, and #1412 currently sits on the #1392 side: it keeps the existing
nan_to_numon both operands, so onraa, where[1982, 120]is NaN,NaN < 10000andNaN <= 10000both come backTrue(NaN read as 0) while>and>=areFalse. pandas givesFalsefor all four.whichever way @genedan calls it, it is a small change in the shared
_comparehelper that PR adds: drop thenan_to_numand let NaN propagate so every comparison isFalse, or keep it as is. happy to switch it over, I just did not want to change NaN semantics quietly while fixing the operators.genedan commentedon Sep 22, 2026
Oh yeah...those NaNs always trip me up, I was so hyperfocused on the 5012.0 cell that I wasn't paying attention to the NaNs.
5012.0 <= 5012.0should resolve toTrue, so that part of #1392 is definitely a bug.The
NaNcomparison in the lower diagonal should also evaluate toFalse.I did find the standard that Python follows, it's IEEE 754, this specifies that NaN comparisons should evaluate to
False.