From 7b65f6ff3f636499e4a2f7ede0710357b60a2d33 Mon Sep 17 00:00:00 2001 From: Gourav Kumar Date: Sun, 11 Sep 2022 15:13:06 +0530 Subject: [PATCH] find closest date returns nan for min/max failure as well --- pyfacts/utils.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pyfacts/utils.py b/pyfacts/utils.py index f212101..9cc4e2e 100644 --- a/pyfacts/utils.py +++ b/pyfacts/utils.py @@ -188,9 +188,15 @@ def _find_closest_date( """ if delta.days < 0 and date < min(data.data): - raise DateOutOfRangeError(date, "min") + if if_not_found == "nan": + return float("NaN"), float("NaN") + else: + raise DateOutOfRangeError(date, "min") if delta.days > 0 and date > max(data.data): - raise DateOutOfRangeError(date, "max") + if if_not_found == "nan": + return float("NaN"), float("NaN") + else: + raise DateOutOfRangeError(date, "max") row: tuple = data.get(date, None) if row is not None: