From 44f7ca5dff1d84caab28503d989c4c8474b4d966 Mon Sep 17 00:00:00 2001 From: Kevin Johnson Date: Sat, 13 Mar 2021 15:18:44 -0800 Subject: [PATCH] DEP removed mp property ENH new last_run, time_range and to_utc properties --- README.md | 28 ++++++++++++++++++++++++- pandas_ta/core.py | 44 +++++++++++++++++++--------------------- pandas_ta/utils/_time.py | 4 ---- setup.py | 2 +- 4 files changed, 49 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index 91ba53a..13ade6c 100644 --- a/README.md +++ b/README.md @@ -424,6 +424,13 @@ df.ta.cores df.ta.datetime_ordered ``` +## **last_run** + +```python +# Returns the time Pandas TA was last run as a string. +df.ta.last_run +``` + ## **reverse** ```python @@ -448,6 +455,25 @@ bothhl2 = df.ta.hl2(prefix="pre", suffix="post") print(bothhl2.name) # "pre_HL2_post" ``` +## **time_range** + +```python +# Returns the time range of the DataFrame as a float. +# By default, it returns the time in "years" +df.ta.time_range + +# Available time_ranges include: "years", "months", "weeks", "days", "hours", "minutes". "seconds" +df.ta.time_range = "days" +df.ta.time_range # prints DataFrame time in "days" as float +``` + +## **to_utc** + +```python +# Sets the DataFrame index to UTC format. +df.ta.to_utc +``` +

# **Indicators** (_by Category_) @@ -687,7 +713,7 @@ result = ta.cagr(df.close) * **Moving Average Choices**: dema, ema, fwma, hma, linreg, midpoint, pwma, rma, sinwma, sma, swma, t3, tema, trima, vidya, wma, zlma. * An _experimental_ and independent __Watchlist__ Class located in the [Examples](https://github.com/twopirllc/pandas-ta/tree/master/examples/watchlist.py) Directory that can be used in conjunction with the new __Strategy__ Class. * _Linear Regression_ (**linear_regression**) is a new utility method for Simple Linear Regression using _Numpy_ or _Scikit Learn_'s implementation. -* Added utility/convience function, ```to_utc```, to convert the DataFrame index to UTC. See: ```help(ta.to_utc)``` +* Added utility/convience function, ```to_utc```, to convert the DataFrame index to UTC. See: ```help(ta.to_utc)``` **Now** as a Pandas TA DataFrame Property to easily convert the DataFrame index to UTC.
diff --git a/pandas_ta/core.py b/pandas_ta/core.py index 3896ab7..db9669e 100644 --- a/pandas_ta/core.py +++ b/pandas_ta/core.py @@ -50,8 +50,8 @@ class Strategy: ta: List = field(default_factory=list) # Required. # Helpful. More descriptive version or notes or w/e. description: str = "TA Description" - # Optional. May change type later to datetime - created: str = datetime.now().strftime("%m/%d/%Y, %H:%M:%S") + # Optional. Gets Exchange Time and Local Time execution time + created: str = get_time(to_string=True) def __post_init__(self): has_name = True @@ -234,8 +234,8 @@ class AnalysisIndicators(BasePandasObject): _adjusted = None _cores = cpu_count() - _mp = False _time_range = "years" + _last_run = get_time(to_string=True) # DataFrame Behavioral Methods def __call__( @@ -253,6 +253,7 @@ class AnalysisIndicators(BasePandasObject): # Run the indicator result = fn(**kwargs) # = getattr(self, kind)(**kwargs) + self._last_run = get_time(to_string=True) # Save when it completed it's run if timed: result.timed = final_time(stime) @@ -294,17 +295,9 @@ class AnalysisIndicators(BasePandasObject): self._cores = cpus @property - def mp(self) -> bool: - """property: df.ta.mp""" - return self._mp - - @mp.setter - def mp(self, value: bool) -> None: - """property: df.ta.mp = False (Default)""" - if value is not None and isinstance(value, bool): - self._mp = value - else: - self._mp = False + def last_run(self) -> str: + """Returns the time when the DataFrame was last run.""" + return self._last_run # Public Get DataFrame Properties @property @@ -326,18 +319,23 @@ class AnalysisIndicators(BasePandasObject): return self._df.iloc[::-1] @property - def time_range(self) -> str: - """""" + def time_range(self) -> float: + """Returns the time ranges of the DataFrame as a float. Default is in "years". help(ta.toal_time)""" return total_time(self._df, self._time_range) @time_range.setter def time_range(self, value: str) -> None: - """property: df.ta.mp = False (Default)""" + """property: df.ta.time_range = "years" (Default)""" if value is not None and isinstance(value, str): self._time_range = value else: self._time_range = "years" + @property + def to_utc(self) -> None: + """Sets the DataFrame index to UTC format""" + self._df = to_utc(self._df) + @property def version(self) -> str: """Returns the version.""" @@ -540,9 +538,10 @@ class AnalysisIndicators(BasePandasObject): "categories", "cores", "datetime_ordered", - "mp", + "last_run", "reverse", "time_range", + "to_utc", "version", ] @@ -671,7 +670,7 @@ class AnalysisIndicators(BasePandasObject): # Some magic to optimize chunksize for speed based on total ta indicators _chunksize = mp_chunksize - 1 if mp_chunksize > _total_ta else int(npLog10(_total_ta)) + 1 if verbose: - print(f"[i] Multiprocessing: {_chunksize} chunks over {cpu_count()} cores for {_total_ta} indicators.") + print(f"[i] Multiprocessing {_total_ta} indicators with {_chunksize} chunks over {self.cores}/{cpu_count()} cpus.") results = None if mode["custom"]: @@ -697,6 +696,7 @@ class AnalysisIndicators(BasePandasObject): pool.close() pool.join() + self._last_run = get_time(to_string=True) else: # Without multiprocessing: @@ -718,14 +718,12 @@ class AnalysisIndicators(BasePandasObject): # DataFrame [self._post_process(r, **kwargs) for r in results] - if timed: - ftime = final_time(stime) - if verbose: print(f"[i] Total indicators: {len(ta)}") print(f"[i] Columns added: {len(self._df.columns) - initial_column_count}") + print(f"[i] Last Run: {self._last_run}") if timed: - print(f"[i] Runtime: {ftime}") + print(f"[i] Runtime: {final_time(stime)}") # Public DataFrame Methods: Indicators and Utilities # Candles diff --git a/pandas_ta/utils/_time.py b/pandas_ta/utils/_time.py index 79d7cd6..0696f06 100644 --- a/pandas_ta/utils/_time.py +++ b/pandas_ta/utils/_time.py @@ -19,10 +19,6 @@ def df_dates(df: DataFrame, dates: Tuple[str, list] = None) -> DataFrame: def df_month_to_date(df: DataFrame) -> DataFrame: """Yields the Month-to-Date (MTD) DataFrame""" - # if df.empty: print("[X] Month-to-Date not in range"); return - # print(df.shape) - # print(type(df)) - # print(df) return df[df.index >= Timestamp.now().strftime("%Y-%m-01")] diff --git a/setup.py b/setup.py index ab89237..5d0c54d 100644 --- a/setup.py +++ b/setup.py @@ -18,7 +18,7 @@ setup( "pandas_ta.volatility", "pandas_ta.volume" ], - version=".".join(("0", "2", "50b")), + version=".".join(("0", "2", "51b")), description=long_description, long_description=long_description, author="Kevin Johnson",