changed pos = [] to *pos in date_parser decorator

This commit is contained in:
Gourav Kumar 2022-03-01 15:34:16 +05:30
parent 347634f536
commit 60f25de710
2 changed files with 4 additions and 4 deletions

View File

@ -17,14 +17,14 @@ class Frequency:
symbol: str symbol: str
def date_parser(pos): def date_parser(*pos):
def parse_dates(func): def parse_dates(func):
def wrapper_func(*args, **kwargs): def wrapper_func(*args, **kwargs):
date_format = kwargs.get("date_format", None) date_format = kwargs.get("date_format", None)
args = list(args) args = list(args)
sig = inspect.signature(func) sig = inspect.signature(func)
params = [i[0] for i in sig.parameters.items()] params = [i[0] for i in sig.parameters.items()]
# print(params)
for j in pos: for j in pos:
kwarg = params[j] kwarg = params[j]
date = kwargs.get(kwarg, None) date = kwargs.get(kwarg, None)

View File

@ -184,7 +184,7 @@ class TimeSeries(TimeSeriesCore):
return self.__class__(new_ts, frequency=self.frequency.symbol) return self.__class__(new_ts, frequency=self.frequency.symbol)
@date_parser(pos=[1]) @date_parser(1)
def calculate_returns( def calculate_returns(
self, self,
as_on: Union[str, datetime.datetime], as_on: Union[str, datetime.datetime],
@ -277,7 +277,7 @@ class TimeSeries(TimeSeriesCore):
returns = returns ** (1 / years) returns = returns ** (1 / years)
return (current[0] if return_actual_date else as_on), returns - 1 return (current[0] if return_actual_date else as_on), returns - 1
@date_parser(pos=[1, 2]) @date_parser(1, 2)
def calculate_rolling_returns( def calculate_rolling_returns(
self, self,
from_date: Union[datetime.date, str], from_date: Union[datetime.date, str],