implemented getitem in Series to prevent error
This commit is contained in:
parent
3391f04e19
commit
b99f0d67c1
@ -108,9 +108,9 @@ def _parse_date(date: str, date_format: str = None):
|
|||||||
try:
|
try:
|
||||||
date = datetime.datetime.strptime(date, date_format)
|
date = datetime.datetime.strptime(date, date_format)
|
||||||
except TypeError:
|
except TypeError:
|
||||||
raise Exception("Date does not seem to be valid date-like string")
|
raise ValueError("Date does not seem to be valid date-like string")
|
||||||
except ValueError:
|
except ValueError:
|
||||||
raise Exception("Date could not be parsed. Have you set the correct date format in FincalOptions.date_format?")
|
raise ValueError("Date could not be parsed. Have you set the correct date format in FincalOptions.date_format?")
|
||||||
return date
|
return date
|
||||||
|
|
||||||
|
|
||||||
@ -156,6 +156,12 @@ class Series(UserList):
|
|||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return f"{self.__class__.__name__}({self.data})"
|
return f"{self.__class__.__name__}({self.data})"
|
||||||
|
|
||||||
|
def __getitem__(self, i):
|
||||||
|
if isinstance(i, slice):
|
||||||
|
return self.__class__(self.data[i], self.dtype)
|
||||||
|
else:
|
||||||
|
return self.data[i]
|
||||||
|
|
||||||
def __gt__(self, other):
|
def __gt__(self, other):
|
||||||
if self.dtype == bool:
|
if self.dtype == bool:
|
||||||
raise TypeError("> not supported for boolean series")
|
raise TypeError("> not supported for boolean series")
|
||||||
@ -299,7 +305,7 @@ class TimeSeriesCore(UserDict):
|
|||||||
else:
|
else:
|
||||||
dates_to_return = [self.dates[i] for i, j in enumerate(key) if j]
|
dates_to_return = [self.dates[i] for i, j in enumerate(key) if j]
|
||||||
data_to_return = [(key, self.data[key]) for key in dates_to_return]
|
data_to_return = [(key, self.data[key]) for key in dates_to_return]
|
||||||
return TimeSeriesCore(data_to_return, frequency=self.frequency.symbol)
|
return self.__class__(data_to_return, frequency=self.frequency.symbol)
|
||||||
|
|
||||||
if isinstance(key, int):
|
if isinstance(key, int):
|
||||||
raise KeyError(f"{key}. For index based slicing, use .iloc[{key}]")
|
raise KeyError(f"{key}. For index based slicing, use .iloc[{key}]")
|
||||||
|
Loading…
Reference in New Issue
Block a user