created decorator function, yet to be implemented

This commit is contained in:
Gourav Kumar 2022-02-27 14:49:50 +05:30
parent ad68dcd930
commit 00ac66219b
2 changed files with 21 additions and 2 deletions

View File

@ -43,6 +43,23 @@ class _IndexSlicer:
return item
def date_parser(*params):
def parse_dates(func):
def wrapper_func(*args, **kwargs):
date_format = kwargs.get('date_format', None)
for i, j in enumerate(params):
date = kwargs.get(j, None)
if date is None:
date = args[i+1]
parsed_date = _parse_date(date, date_format)
kwargs[j] = parsed_date
return func(**kwargs)
return wrapper_func
return parse_dates
class Series(UserList):
"""Container for a series of objects, all objects must be of the same type"""
@ -157,7 +174,7 @@ class TimeSeriesCore(UserDict):
def __init__(
self, data: List[Iterable], frequency: Literal["D", "W", "M", "Q", "H", "Y"], date_format: str = "%Y-%m-%d"
):
"""Instantiate a TimeSeries object
"""Instantiate a TimeSeriesCore object
Parameters
----------

View File

@ -5,7 +5,7 @@ from typing import Iterable, List, Literal, Mapping, Union
from dateutil.relativedelta import relativedelta
from .core import AllFrequencies, TimeSeriesCore
from .core import AllFrequencies, TimeSeriesCore, date_parser
from .utils import (
_find_closest_date,
_interval_to_years,
@ -184,6 +184,7 @@ class TimeSeries(TimeSeriesCore):
return self.__class__(new_ts, frequency=self.frequency.symbol)
# @date_parser('as_on')
def calculate_returns(
self,
as_on: Union[str, datetime.datetime],
@ -276,6 +277,7 @@ class TimeSeries(TimeSeriesCore):
returns = returns ** (1 / years)
return (current[0] if return_actual_date else as_on), returns - 1
# @date_parser('from_date', 'to_date')
def calculate_rolling_returns(
self,
from_date: Union[datetime.date, str],