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
4 changes: 2 additions & 2 deletions dcaf/streams/cashflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ def sort(
descending: bool = ...,
) -> "CashFlowStream": ...
@overload
def sort(self) -> "CashFlowStream": ...
def sort(self, *, descending: bool = ...) -> "CashFlowStream": ...

def sort(
self,
Expand Down Expand Up @@ -712,7 +712,7 @@ def sort(
if fn is not None:
return super().sort(fn, descending=descending)
if attr is None:
return super().sort()
return super().sort(attr="date", descending=descending)
return super().sort(attr=attr, descending=descending)

def scale(self, factor: float) -> "CashFlowStream":
Expand Down
10 changes: 8 additions & 2 deletions tests/unit/test_cashflow_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,7 @@ def test_from_recurring_annual_escalation_is_date_based():
)
expected_dates = [date(2026, 4, 4), date(2026, 5, 4), date(2026, 6, 4)]
expected_amounts = [
-200.0 * _annual_factor(date(2026, 3, 5), flow_date, 0.1)
for flow_date in expected_dates
-200.0 * _annual_factor(date(2026, 3, 5), flow_date, 0.1) for flow_date in expected_dates
]
for i, flow in enumerate(cf_stream.entries):
assert flow.date == expected_dates[i]
Expand Down Expand Up @@ -888,6 +887,13 @@ def test_sort_bare_call_sorts_by_date(_create_cf_stream):
assert result.entries == [flows[0], flows[1], flows[2], flows[3]]


def test_sort_default_attribute_descending(_create_cf_stream):
"""sort(descending=True) sorts by the default date attribute descending."""
cf_stream, flows = _create_cf_stream
result = cf_stream.sort(descending=True)
assert result.entries == [flows[3], flows[2], flows[1], flows[0]]


def test_sort_attr_amount_descending(_create_cf_stream):
"""sort(attr='amount', descending=True) sorts by amount descending."""
cf_stream, flows = _create_cf_stream
Expand Down