From cc1d6dd6e22daa6743495314d6e157afd2d5522e Mon Sep 17 00:00:00 2001 From: Kevin Johnson Date: Mon, 5 Jul 2021 14:35:43 -0700 Subject: [PATCH] MAINT suppress pd performance warning ENH df init and validation --- pandas_ta/core.py | 27 +++++++++++++++------------ tests/test_ext_indicator_candle.py | 3 +-- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/pandas_ta/core.py b/pandas_ta/core.py index 72dd07c..07f54ac 100644 --- a/pandas_ta/core.py +++ b/pandas_ta/core.py @@ -4,6 +4,7 @@ from multiprocessing import cpu_count, Pool from pathlib import Path from time import perf_counter from typing import List, Tuple +from warnings import simplefilter import pandas as pd from numpy import log10 as npLog10 @@ -250,15 +251,15 @@ class AnalysisIndicators(BasePandasObject): _time_range = "years" _last_run = get_time(_exchange, to_string=True) - # def __init__(self, pandas_obj): - # # self._validate(pandas_obj) - # self._df = pandas_obj - # self._last_run = get_time(self._exchange, to_string=True) + def __init__(self, pandas_obj): + self._validate(pandas_obj) + self._df = pandas_obj + self._last_run = get_time(self._exchange, to_string=True) - # @staticmethod - # def _validate(df: Tuple[pd.DataFrame, pd.Series]): - # if isinstance(df, pd.Series) or isinstance(df, pd.DataFrame): - # raise AttributeError("[X] Must be either a Pandas Series or DataFrame.") + @staticmethod + def _validate(obj: Tuple[pd.DataFrame, pd.Series]): + if not isinstance(obj, pd.DataFrame) and not isinstance(obj, pd.Series): + raise AttributeError("[X] Must be either a Pandas Series or DataFrame.") # DataFrame Behavioral Methods def __call__( @@ -400,8 +401,9 @@ class AnalysisIndicators(BasePandasObject): df = self._df if df is None or result is None: return else: + simplefilter(action="ignore", category=pd.errors.PerformanceWarning) if "col_names" in kwargs and not isinstance(kwargs["col_names"], tuple): - kwargs["col_names"] = (kwargs["col_names"],) + kwargs["col_names"] = (kwargs["col_names"],) # Note: tuple(kwargs["col_names"]) doesn't work if isinstance(result, pd.DataFrame): # If specified in kwargs, rename the columns. @@ -761,10 +763,10 @@ class AnalysisIndicators(BasePandasObject): else: # Without multiprocessing: if verbose: + _col_msg = f"[i] No mulitproccessing (cores = 0)." if has_col_names: - print(f"[i] No mulitproccessing support for 'col_names' option.") - else: - print(f"[i] No mulitproccessing (cores = 0).") + _col_msg = f"[i] No mulitproccessing support for 'col_names' option." + print(_col_msg) if mode["custom"]: if Imports["tqdm"] and verbose: @@ -784,6 +786,7 @@ class AnalysisIndicators(BasePandasObject): else: for ind in ta: getattr(self, ind)(*tuple(), **kwargs) + self._last_run = get_time(self.exchange, to_string=True) # Apply prefixes/suffixes and appends indicator results to the DataFrame [self._post_process(r, **kwargs) for r in results] diff --git a/tests/test_ext_indicator_candle.py b/tests/test_ext_indicator_candle.py index 787040c..55ba9d7 100644 --- a/tests/test_ext_indicator_candle.py +++ b/tests/test_ext_indicator_candle.py @@ -1,7 +1,7 @@ from .config import sample_data from .context import pandas_ta -from unittest import TestCase +from unittest import TestCase, skip from pandas import DataFrame @@ -17,7 +17,6 @@ class TestCandleExtension(TestCase): def setUp(self): pass def tearDown(self): pass - def test_cdl_doji_ext(self): self.data.ta.cdl_pattern("doji", append=True) self.assertIsInstance(self.data, DataFrame)