Fixing fa/ bugs (#4524)

* Fix fraud showing nothing when NA values

* Fix sdk

* fix #4457

* sdk generation tests

---------

Co-authored-by: teh_coderer <me@tehcoderer.com>
This commit is contained in:
James Maslek
2023-03-20 10:54:07 -04:00
committed by GitHub
parent 890cc87f19
commit cceeb3e2b6
18 changed files with 4712 additions and 4689 deletions

View File

@@ -24,7 +24,7 @@ repos:
entry: codespell
args:
[
"--ignore-words-list=gard,te,commun,ro,zar,vie,hel,jewl,zlot,ba,buil,coo,ether,hist,hsi,mape,navagation,operatio,pres,ser,yeld,shold,ist,varian,datas,ake,creat,statics,ket,toke,certi,buidl,ot",
"--ignore-words-list=shs,gard,te,commun,ro,zar,vie,hel,jewl,zlot,ba,buil,coo,ether,hist,hsi,mape,navagation,operatio,pres,ser,yeld,shold,ist,varian,datas,ake,creat,statics,ket,toke,certi,buidl,ot",
"--quiet-level=2",
"--skip=./tests,.git,*.css,*.csv,*.html,*.ini,*.ipynb,*.js,*.json,*.lock,*.scss,*.txt,*.yaml,build/pyinstaller/*,./website/config.toml",
]

View File

@@ -535,7 +535,7 @@ class BuildCategoryModelClasses:
subprocess.check_call(["black", "openbb_terminal"]) # nosec: B603, B607
def generate_sdk(sort: bool = False) -> None:
def generate_sdk(sort: bool = False) -> bool:
"""Generate the SDK.
Parameters
@@ -544,11 +544,15 @@ def generate_sdk(sort: bool = False) -> None:
Whether to sort the CSVs, by default False
"""
trailmaps = get_trailmaps(sort)
try:
console.print("[yellow]Generating SDK...[/]")
BuildCategoryModelClasses(trailmaps).build()
console.print("[green]SDK Generated Successfully.[/]")
except Exception as e:
console.print(f"[red]Error generating SDK: {e}[/]")
return False
console.print("[yellow]Generating SDK...[/]")
BuildCategoryModelClasses(trailmaps).build()
console.print("[green]SDK Generated Successfully.[/]")
return
return True
if __name__ == "__main__":

View File

@@ -356,7 +356,7 @@ cfg.start_required_configurations()
cfg.start_plot_backend()
logger = logging.getLogger(__name__)
theme.applyMPLstyle()
cfg.theme.applyMPLstyle()
\r\r\r
"""
return "\r".join(sdk_imports.splitlines())

View File

@@ -282,7 +282,6 @@ keys.messari,keys_model.set_messari_key,
keys.mykeys,keys_model.get_keys,
keys.news,keys_model.set_news_key,
keys.oanda,keys_model.set_oanda_key,
keys.openbb,keys_model.set_openbb_personal_access_token,
keys.polygon,keys_model.set_polygon_key,
keys.quandl,keys_model.set_quandl_key,
keys.reddit,keys_model.set_reddit_key,
1 trail model view
282 keys.mykeys keys_model.get_keys
283 keys.news keys_model.set_news_key
284 keys.oanda keys_model.set_oanda_key
keys.openbb keys_model.set_openbb_personal_access_token
285 keys.polygon keys_model.set_polygon_key
286 keys.quandl keys_model.set_quandl_key
287 keys.reddit keys_model.set_reddit_key

View File

@@ -27,6 +27,7 @@ cfg.start_required_configurations()
cfg.start_plot_backend()
logger = logging.getLogger(__name__)
cfg.theme.applyMPLstyle()
class OpenBBSDK:

View File

@@ -558,8 +558,7 @@ def replace_df(name: str, row: pd.Series) -> pd.Series:
elif name in ["Zscore", "McKee"]:
row[i] = color_zscore_mckee(item)
else:
row[i] = str(round(float(item), 2))
row[i] = str(round(float(item), 2)) if item != "nan" else "N/A"
return row
@@ -576,6 +575,8 @@ def color_mscore(value: str) -> str:
new_value : str
The string formatted with rich color
"""
if value == "nan":
return "N/A"
value_float = float(value)
if value_float <= -2.22:
return f"[green]{value_float:.2f}[/green]"
@@ -596,6 +597,8 @@ def color_zscore_mckee(value: str) -> str:
new_value : str
The string formatted with rich color
"""
if value == "nan":
return "N/A"
value_float = float(value)
if value_float < 0.5:
return f"[red]{value_float:.2f}[/red]"
@@ -714,7 +717,7 @@ def get_fraud_ratios(symbol: str, detail: bool = False) -> pd.DataFrame:
"Zscore",
"Mckee",
]:
ratios[item] = "N/A"
ratios[item] = np.nan
if fraud_years.empty:
fraud_years.index = ratios.keys()
fraud_years[df_cf.index[i]] = ratios.values()

View File

@@ -445,6 +445,7 @@ def display_fraud(
df = av_model.get_fraud_ratios(symbol, detail=detail)
if df.empty:
console.print("[red]No data found[/red]")
return
df_color = df.copy()
@@ -452,7 +453,7 @@ def display_fraud(
for column in df_color:
df_color[column] = df_color[column].astype(str)
df_color = df_color.apply(lambda x: av_model.replace_df(x.name, x), axis=1)
df_color = df_color.fillna("N/A")
print_rich_table(
df_color,
headers=list(df_color.columns),

View File

@@ -1487,7 +1487,6 @@ class FundamentalAnalysisController(StockBaseController):
if not self.ticker:
console.print(no_ticker_message)
return
av_view.display_fraud(
symbol=self.ticker,
export=ns_parser.export,

View File

@@ -7,6 +7,7 @@ from typing import Any, Dict, List
import finviz
import pandas as pd
import requests
from openbb_terminal.decorators import log_start_end
from openbb_terminal.rich_config import console
@@ -33,7 +34,10 @@ def get_data(symbol: str) -> pd.DataFrame:
>>> from openbb_terminal.sdk import openbb
>>> openbb.stocks.fa.data("IWV")
"""
d_finviz_stock = finviz.get_stock(symbol)
try:
d_finviz_stock = finviz.get_stock(symbol)
except requests.exceptions.HTTPError:
return pd.DataFrame()
df_fa = pd.DataFrame.from_dict(d_finviz_stock, orient="index", columns=["Values"])
return df_fa[df_fa.Values != "-"]

View File

@@ -9,6 +9,7 @@ from openbb_terminal import rich_config
from openbb_terminal.core.session.current_user import get_current_user
from openbb_terminal.decorators import log_start_end
from openbb_terminal.helper_funcs import export_data, print_rich_table
from openbb_terminal.rich_config import console
from openbb_terminal.stocks.fundamental_analysis import finviz_model
logger = logging.getLogger(__name__)
@@ -29,6 +30,10 @@ def display_screen_data(
"""
fund_data = finviz_model.get_data(symbol)
if fund_data.empty:
console.print(f"No data found for {symbol}", style="bold red")
return
print_rich_table(
fund_data, title="Ticker Screener", show_index=True, export=bool(export)
)

View File

@@ -0,0 +1 @@
[red]No data found[/red]

View File

@@ -0,0 +1,6 @@
from generate_sdk import generate_sdk
def test_sdk_generation():
"""Test the sdk markdown generator"""
assert generate_sdk() is True