Skip to content

Commit

Permalink
hotfix/fa-yfinance-plot - makes stocks/fa/income --plot output matc…
Browse files Browse the repository at this point in the history
…h everything else. (#5101)

* makes fa/plot output match everything else

* fix y-axis to be billions

* fix denominations

* black

* ruff
  • Loading branch information
deeleeramone authored Jun 5, 2023
1 parent f4a5064 commit b81aa22
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 33 deletions.
15 changes: 5 additions & 10 deletions openbb_terminal/stocks/fundamental_analysis/yahoo_finance_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
__docformat__ = "numpy"

import logging
import re
import ssl
from datetime import datetime
from typing import Optional, Tuple
Expand All @@ -15,7 +14,6 @@

from openbb_terminal.decorators import log_start_end
from openbb_terminal.helper_funcs import lambda_long_number_format
from openbb_terminal.helpers_denomination import transform as transform_by_denomination
from openbb_terminal.rich_config import console
from openbb_terminal.stocks.fundamental_analysis.fa_helper import clean_df_index

Expand Down Expand Up @@ -358,14 +356,11 @@ def get_financials(symbol: str, statement: str, ratios: bool = False) -> pd.Data
df = df.replace("k", "", regex=True)
df = df.astype("float")

# Data except EPS is returned in thousands, convert it
(df, _) = transform_by_denomination(
df,
"Thousands",
"Units",
axis=1,
skipPredicate=lambda row: re.search("eps", row.name, re.IGNORECASE) is not None,
)
not_skipped = ~df.reset_index()["Breakdown"].str.contains("EPS", case=False)
skipped = df.reset_index()["Breakdown"].str.contains("EPS", case=False)
skipped_df = df.reset_index()[skipped].set_index("Breakdown")
transformed = df.reset_index()[not_skipped].set_index("Breakdown") * 1000
df = pd.concat([transformed, skipped_df])

if ratios:
types = df.copy().applymap(lambda x: isinstance(x, (float, int)))
Expand Down
33 changes: 10 additions & 23 deletions openbb_terminal/stocks/fundamental_analysis/yahoo_finance_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
lambda_long_number_format,
print_rich_table,
)
from openbb_terminal.helpers_denomination import transform as transform_by_denomination
from openbb_terminal.rich_config import console
from openbb_terminal.stocks import stocks_helper
from openbb_terminal.stocks.fundamental_analysis import yahoo_finance_model
Expand Down Expand Up @@ -392,8 +391,6 @@ def display_fundamentals(
for i in [i.replace(" ", "_") for i in fundamentals.index.str.lower()]
]

symbol_currency = yahoo_finance_model.get_currency(symbol)

if plot:
plot = [x.lower() for x in plot]
rows_plot = len(plot)
Expand All @@ -403,40 +400,29 @@ def display_fundamentals(
fundamentals_plot_data = fundamentals_plot_data.drop(["ttm"])
fundamentals_plot_data = fundamentals_plot_data.sort_index()

if not ratios:
maximum_value = fundamentals_plot_data[plot[0]].max()
(df_rounded, denomination) = transform_by_denomination(
fundamentals_plot_data, maxValue=maximum_value
)
if denomination == "Units":
denomination = ""
else:
df_rounded = fundamentals_plot_data
denomination = ""

if rows_plot == 1:
fig.add_bar(
x=df_rounded.index,
y=df_rounded[plot[0]],
fig.add_scatter(
x=fundamentals_plot_data.index,
y=fundamentals_plot_data[plot[0]],
name=plot[0].replace("_", " "),
)
title = (
f"{plot[0].replace('_', ' ').capitalize()} QoQ Growth of {symbol.upper()}"
if ratios
else f"{plot[0].replace('_', ' ').capitalize()} of {symbol.upper()} {denomination}"
else f"{plot[0].replace('_', ' ').capitalize()} of {symbol.upper()}"
)
fig.set_title(title)
else:
fig = OpenBBFigure.create_subplots(rows=rows_plot, cols=1)
for i in range(rows_plot):
fig.add_bar(
x=df_rounded.index,
y=df_rounded[plot[i]],
fig.add_scatter(
x=fundamentals_plot_data.index,
y=fundamentals_plot_data[plot[i]],
name=plot[i].replace("_", " "),
row=i + 1,
col=1,
)
title = f"{plot[i].replace('_', ' ')} {denomination}"
title = f"{plot[i].replace('_', ' ')}"
fig.add_annotation(x=0.5, y=1, row=i + 1, col=1, text=title)

fig.show(external=fig.is_image_export(export))
Expand All @@ -451,7 +437,8 @@ def display_fundamentals(
print_rich_table(
formatted_df.applymap(lambda x: "-" if x == "nan" else x),
show_index=True,
title=f"{symbol} {title_str} Currency: {symbol_currency}",
index_name="Item",
title=f"{symbol} {title_str}",
export=bool(export),
limit=limit,
)
Expand Down

0 comments on commit b81aa22

Please sign in to comment.