Skip to content

Commit

Permalink
hotfix / TA ma's empty if not enough data for window (OpenBB-finance#…
Browse files Browse the repository at this point in the history
…5180)

* fix: TA ma's empty if not enough data for window

* Update test_load_options.yaml
  • Loading branch information
tehcoderer authored Jun 24, 2023
1 parent 4bc4368 commit d2ed7c2
Show file tree
Hide file tree
Showing 2 changed files with 1,912 additions and 3 deletions.
17 changes: 14 additions & 3 deletions openbb_terminal/core/plots/plotly_ta/data_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ def get_indicator_data(self, indicator: TAIndicator, **args) -> pd.DataFrame:
pd.DataFrame
Dataframe with indicator data
"""
output = None
output: Optional[pd.DataFrame] = None
if indicator and indicator.name in self.ma_mode:
if isinstance(indicator.get_argument_values("length"), list):
df_ta = pd.DataFrame()
Expand All @@ -264,6 +264,12 @@ def get_indicator_data(self, indicator: TAIndicator, **args) -> pd.DataFrame:
df_ma = getattr(ta, indicator.name)(
self.df_ta[self.close_col], length=length
)
if not isinstance(df_ma, pd.Series) or df_ma.empty:
console.print(
f"Error processing {indicator.name.upper()}({length}) not enough data",
style="bold red",
)
continue
df_ta.insert(0, f"{indicator.name.upper()}_{length}", df_ma)

output = df_ta
Expand Down Expand Up @@ -296,8 +302,12 @@ def get_indicator_data(self, indicator: TAIndicator, **args) -> pd.DataFrame:

# Drop NaN values from output and return None if empty
if output is not None:
output.dropna(inplace=True)
output = output.dropna()
if output.empty:
console.print(
f"{indicator.name.upper()} {args} returned empty dataframe",
style="yellow",
)
output = None

return output
Expand Down Expand Up @@ -326,7 +336,8 @@ def to_dataframe(self) -> pd.DataFrame:
)
except Exception as e:
console.print(
f"[red]Error processing indicator {indicator.name}: {e}[/red]"
f"Error processing indicator {indicator.name}: {e}",
style="bold red",
)
indicator_data = None

Expand Down
Loading

0 comments on commit d2ed7c2

Please sign in to comment.