mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-27 12:40:35 +00:00
Improve ca NaN handling + update pre-commit (#980)
This commit is contained in:
10
.pre-commit-config.yaml
vendored
10
.pre-commit-config.yaml
vendored
@@ -27,11 +27,13 @@ repos:
|
||||
hooks:
|
||||
- id: mypy
|
||||
args: [ --ignore-missing-imports ]
|
||||
- repo: https://github.com/pre-commit/mirrors-pylint
|
||||
rev: 'v3.0.0a4'
|
||||
- repo: local
|
||||
hooks:
|
||||
- id: pylint
|
||||
entry: pylint terminal.py gamestonk_terminal tests
|
||||
- id: pylint
|
||||
name: pylint
|
||||
entry: pylint terminal.py gamestonk_terminal tests discordbot
|
||||
language: system
|
||||
types: [python]
|
||||
- repo: https://github.com/Yelp/detect-secrets
|
||||
rev: v1.1.0
|
||||
hooks:
|
||||
|
||||
@@ -52,7 +52,7 @@ def get_historical(
|
||||
# where all tickers are columns.
|
||||
return yf.download(all_tickers, start=start, progress=False, threads=False)[
|
||||
d_candle_types[candle_type]
|
||||
].dropna(axis=1)
|
||||
]
|
||||
|
||||
|
||||
def get_1y_sp500() -> pd.DataFrame:
|
||||
@@ -120,7 +120,7 @@ def get_sp500_comps_tsne(
|
||||
if company != ticker:
|
||||
ax.annotate(company, (x, y), fontsize=9, alpha=0.75)
|
||||
else:
|
||||
ax.scatter(x, y, s=20, c="r")
|
||||
ax.scatter(x, y, s=50, c="r")
|
||||
ax.annotate(company, (x, y), fontsize=9, alpha=1)
|
||||
fig.tight_layout()
|
||||
plt.show()
|
||||
|
||||
@@ -60,7 +60,10 @@ def display_historical(
|
||||
)
|
||||
# To plot with ticker first
|
||||
df_similar = df_similar[ordered_tickers]
|
||||
|
||||
if np.any(df_similar.isna()):
|
||||
nan_tickers = df_similar.columns[df_similar.isna().sum() >= 1].to_list()
|
||||
print(f"NaN values found in: {', '.join(nan_tickers)}. Replacing with zeros.")
|
||||
df_similar = df_similar.fillna(0)
|
||||
fig, ax = plt.subplots(figsize=plot_autoscale(), dpi=PLOT_DPI)
|
||||
# This puts everything on 0-1 scale for visualizing
|
||||
if normalize:
|
||||
@@ -170,7 +173,10 @@ def display_correlation(
|
||||
)
|
||||
# To plot with ticker first
|
||||
df_similar = df_similar[ordered_tickers]
|
||||
|
||||
if np.any(df_similar.isna()):
|
||||
nan_tickers = df_similar.columns[df_similar.isna().sum() >= 1].to_list()
|
||||
print(f"NaN values found in: {', '.join(nan_tickers)}. Backfilling data")
|
||||
df_similar = df_similar.fillna(method="bfill")
|
||||
mask = np.zeros((df_similar.shape[1], df_similar.shape[1]), dtype=bool)
|
||||
mask[np.triu_indices(len(mask))] = True
|
||||
|
||||
|
||||
Reference in New Issue
Block a user