Browse Source

Implemented DateOutOfRange error in find closes date

switch-to-decimal
Gourav Kumar 2 years ago
parent
commit
336276cf4b
  1. 2
      fincal/fincal.py
  2. 7
      fincal/utils.py

2
fincal/fincal.py

@ -125,7 +125,7 @@ class TimeSeries(TimeSeriesCore):
return_actual_date: bool = True,
as_on_match: str = "closest",
prior_match: str = "closest",
closest: str = "previous",
closest: Literal["previous", "next", "exact"] = 'previous',
if_not_found: Literal['fail', 'nan'] = 'fail',
compounding: bool = True,
interval_type: Literal['years', 'months', 'days'] = 'years',

7
fincal/utils.py

@ -2,7 +2,7 @@ import datetime
from dataclasses import dataclass
from typing import Iterable, List, Literal, Mapping, Sequence, Tuple, Union
from .exceptions import DateNotFoundError
from .exceptions import DateNotFoundError, DateOutOfRangeError
@dataclass
@ -88,6 +88,11 @@ def _preprocess_match_options(as_on_match: str, prior_match: str, closest: str)
def _find_closest_date(data, date, delta, if_not_found):
"""Helper function to find data for the closest available date"""
if delta.days < 0 and date < min(data):
raise DateOutOfRangeError(date, 'min')
if delta.days > 0 and date > max(data):
raise DateOutOfRangeError(date, 'max')
row = data.get(date, None)
if row is not None:
return date, row

Loading…
Cancel
Save