Skip to content

Commit

Permalink
Remove default condense method
Browse files Browse the repository at this point in the history
  • Loading branch information
LeeDongGeon1996 committed Apr 28, 2024
1 parent aa06ff2 commit 0e04237
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 16 deletions.
16 changes: 9 additions & 7 deletions stock_indicators/indicators/common/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

from typing_extensions import Self

from stock_indicators._cslib import CsIndicator, CsIEnumerable
from stock_indicators._cslib import CsIndicator, CsIEnumerable, CsResultUtility
from stock_indicators._cstypes import List as CsList
from stock_indicators.indicators.common.results import IndicatorResults


class RemoveWarmupMixin:
"""Mixin for remove_warmup_periods()."""
"""IndicatorResults Mixin for remove_warmup_periods()."""
@IndicatorResults._verify_data
def remove_warmup_periods(self: IndicatorResults, remove_periods: Optional[int] = None) -> Self:
"""
Expand All @@ -22,15 +22,17 @@ def remove_warmup_periods(self: IndicatorResults, remove_periods: Optional[int]


class CondenseMixin:
"""Mixin for condense()."""
"""IndicatorResults Mixin for condense()."""
@IndicatorResults._verify_data
def condense(self: IndicatorResults) -> Self:
"""
Removes non-essential records containing null values with unique consideration for this indicator.
"""
cs_results_type = self._get_csdata_type()
try: # to check whether there's matched overloaded method.
condense_method = CsIndicator.Condense.Overloads[CsIEnumerable[self._get_csdata_type()]]
condensed_results = condense_method(CsList(self._get_csdata_type(), self._csdata))
return self.__class__(condensed_results, self._wrapper_class)
condense_method = CsIndicator.Condense.Overloads[CsIEnumerable[cs_results_type]]
except TypeError:
return super().condense()
condense_method = CsResultUtility.Condense[cs_results_type]

condensed_results = condense_method(CsList(cs_results_type, self._csdata))
return self.__class__(condensed_results, self._wrapper_class)
9 changes: 0 additions & 9 deletions stock_indicators/indicators/common/results.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,6 @@ def remove_warmup_periods(self, remove_periods: int):

return self.__class__(list(self._csdata)[remove_periods:], self._wrapper_class)

@_verify_data
def condense(self):
"""
Removes non-essential records containing null values with unique consideration for this indicator.
"""
cs_results_type = self._get_csdata_type()
condensed_results = CsResultUtility.Condense[cs_results_type](CsList(cs_results_type, self._csdata))
return self.__class__(condensed_results, self._wrapper_class)

def find(self, lookup_date: PyDateTime) -> Optional[_T]:
"""Find indicator values on a specific date. It returns `None` if no result found."""
if not isinstance(lookup_date, PyDateTime):
Expand Down

0 comments on commit 0e04237

Please sign in to comment.