Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion chainladder/core/tests/test_grain.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


def test_grain(qtr):
#this is a dense only test, as grain() follows auto_sparse
#this test is dense only in practice, since grain() applies auto_sparse, which is True by default
actual = qtr.iloc[0, 0].grain("OYDY")
nan = np.nan
expected = np.array(
Expand Down
4 changes: 2 additions & 2 deletions chainladder/core/tests/test_triangle.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,8 +440,8 @@ def test_auto_sparse_disabled_returns_self(prism_convert: Triangle) -> None:

Parameters
----------
prism : Triangle
The prism sample data set Triangle.
prism_convert : Triangle
The prism sample data set Triangle, reduced for test speed.

Returns
-------
Expand Down
2 changes: 1 addition & 1 deletion chainladder/development/tests/test_development.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def __init__(self,dev):

def fit(self, X, y: None = None, sample_weight: None = None):
if hasattr(X,'age_to_age'):
#following precedent _set_fit_groups() from DevelopmentBase
#following precedent set by _set_fit_groups() from DevelopmentBase to force triangle to be dense
backend = "numpy" if X.array_backend in ["sparse", "numpy"] else "cupy"
obj = X.set_backend(backend)
super().fit(obj.incr_to_cum().age_to_age)
Expand Down
1 change: 1 addition & 0 deletions chainladder/methods/mack.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,7 @@ def summary_(self):
# This might be better as a dataframe
obj = self.ultimate_.copy()
backend = obj.array_backend
# forcing these four triangles to the same backend
cols = (
self.X_.latest_diagonal.set_backend(backend).values,
self.ibnr_.set_backend(backend).values,
Expand Down
27 changes: 26 additions & 1 deletion chainladder/utils/tests/test_sparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
array,
floor,
COO,
where
where,
nanquantile
)

from sparse import all as sparse_all

def test_array_from_list_default_fill_value() -> None:
"""
Expand Down Expand Up @@ -111,3 +113,26 @@ def test_floor_returns_copy() -> None:
assert result is not a
np.testing.assert_array_equal(result.todense(), [1.0, 2.0, -1.0])
np.testing.assert_array_equal(a.todense(), [1.2, 2.7, -0.3])

def test_1D_nanquantile() -> None:
"""
Checks that nanquantile performs in 1D special case.

Returns
-------
None
"""
a = COO(np.array([1,2,3,4]))
assert nanquantile(a,0.5) == 2.5

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Faulty nanquantile scalar assertion

Low Severity

nanquantile always returns a COO, so assert nanquantile(a, 0.5) == 2.5 checks truthiness of a boolean COO instead of a scalar. That can error or pass regardless of the value. Nearby checks correctly use sparse_all for COO equality.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 0f76504. Configure here.

assert sparse_all(nanquantile(a,0.5,keepdims = True) == COO(np.array([2.5])))

def test_keepdims_nanquantile() -> None:
"""
Checks that nanquantile keeps dimension when instructed.

Returns
-------
None
"""
a = COO(np.array([[1,2,3,4],[3,4,5,6]]))
assert sparse_all(nanquantile(a,0.5,keepdims = True) == COO(np.array([[2,3,4,5]])))
Loading