From 6cf09392be900e2d257c2c27769023fe73610002 Mon Sep 17 00:00:00 2001 From: teh_coderer Date: Wed, 9 Aug 2023 21:28:29 -0700 Subject: [PATCH] hotfix/ `/stocks/fa/pt` show all price targets on hover (#5305) * `/stocks/fa/pt` show all price targets on hover * Update helper_funcs.py --- openbb_terminal/helper_funcs.py | 5 +++++ .../business_insider_view.py | 16 +++++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/openbb_terminal/helper_funcs.py b/openbb_terminal/helper_funcs.py index c29c09130d40..e93d183cfd5c 100644 --- a/openbb_terminal/helper_funcs.py +++ b/openbb_terminal/helper_funcs.py @@ -278,6 +278,7 @@ def print_rich_table( print_to_console: bool = False, limit: Optional[int] = 1000, source: Optional[str] = None, + columns_keep_types: Optional[List[str]] = None, ): """Prepare a table from df in rich. @@ -313,6 +314,8 @@ def print_rich_table( console. source: Optional[str] Source of the table. If provided, it will be displayed in the header of the table. + columns_keep_types: Optional[List[str]] + Columns to keep their types, i.e. not convert to numeric """ if export: return @@ -329,6 +332,8 @@ def print_rich_table( # convert non-str that are not timestamp or int into str # eg) praw.models.reddit.subreddit.Subreddit for col in df.columns: + if columns_keep_types is not None and col in columns_keep_types: + continue try: if not any( isinstance(df[col].iloc[x], pd.Timestamp) diff --git a/openbb_terminal/stocks/fundamental_analysis/business_insider_view.py b/openbb_terminal/stocks/fundamental_analysis/business_insider_view.py index fb3b42c19ed1..89d92287f4a8 100644 --- a/openbb_terminal/stocks/fundamental_analysis/business_insider_view.py +++ b/openbb_terminal/stocks/fundamental_analysis/business_insider_view.py @@ -172,9 +172,17 @@ def adjust_splits(row, splits: pd.DataFrame): name="Price Target", mode="markers", customdata=df_analyst_plot.apply( - lambda row: f"{row['Company']} ({row['Rating']})", axis=1 - ).values, - hovertemplate="%{customdata}

Price Target: %{y:.2f}", + lambda row: "
".join( + [ + f"${x['Price Target']} - {x['Company']} ({x['Rating']})" + for _, x in df_analyst_plot[df_analyst_plot.index == row.name] + .sort_values(by="Price Target", ascending=False) + .iterrows() + ] + ), + axis=1, + ), + hovertemplate="
%{customdata}", marker=dict( color=colors, line=dict(width=1, color="DarkSlateGrey"), @@ -183,6 +191,8 @@ def adjust_splits(row, splits: pd.DataFrame): line=dict(color=theme.get_colors()[1]), ) + fig.update_layout(hovermode="x unified") + export_data( export, os.path.dirname(os.path.abspath(__file__)),