Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hotfix/fix-gov-histcont: Fix #5650 - /stocks/gov/histcont #5676

Merged
merged 6 commits into from
Nov 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 20 additions & 15 deletions openbb_terminal/stocks/government/quiverquant_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,6 @@ def display_contracts(

if df_contracts.empty:
return

if raw:
print_rich_table(
df_contracts,
Expand All @@ -457,8 +456,8 @@ def display_contracts(

fig.add_bar(
name="Amount",
x=df_contracts["Date"].unique(),
y=df_contracts_grouped["Amount"].values / 1000,
x=sorted(df_contracts["Date"].unique()),
y=df_contracts_grouped["Amount"] / 1000,
)
fig.update_layout(xaxis=dict(type="category"))

Expand Down Expand Up @@ -622,21 +621,25 @@ def display_hist_contracts(
if df_contracts.empty:
return None

amounts = df_contracts.sort_values(by=["Year", "Qtr"])["Amount"].values

qtr = df_contracts.sort_values(by=["Year", "Qtr"])["Qtr"].values
year = df_contracts.sort_values(by=["Year", "Qtr"])["Year"].values
amounts = df_contracts.sort_values(by=["Year", "Qtr"])["Amount"].astype(float)

quarter_ticks = [
f"{quarter[0]}" if quarter[1] == 1 else "" for quarter in zip(year, qtr)
]
date_dict = {
1: "03-31",
2: "06-30",
3: "09-30",
4: "12-31",
}
df_contracts["dates"] = (
df_contracts["Year"].astype(str) + "-" + df_contracts["Qtr"].map(date_dict)
)
df_contracts["dates"] = pd.to_datetime(df_contracts["dates"]).dt.strftime("%Y-%m")
df_contracts.sort_values(by="dates", ascending=True, inplace=True)

fig = OpenBBFigure(
xaxis=dict(
title="Quarter",
tickmode="array",
tickvals=np.arange(0, len(amounts)),
ticktext=quarter_ticks,
ticktext=df_contracts["dates"],
),
yaxis_title="Amount ($1k)",
)
Expand All @@ -660,17 +663,19 @@ def display_hist_contracts(
export,
os.path.dirname(os.path.abspath(__file__)),
"histcont",
df_contracts.drop(columns=["dates"]),
sheet_name=sheet_name,
figure=fig,
)

if raw:
df = df_contracts.drop(columns=["dates"]).astype(str)
return print_rich_table(
df_contracts,
headers=list(df_contracts.columns),
floatfmt=[".0f", ".0f", ".2f"],
df,
headers=list(df.columns),
title="Historical Quarterly Government Contracts",
export=bool(export),
columns_keep_types=["Year"],
)

return fig.show(external=external_axes)
Expand Down
Loading