Skip to content

Commit

Permalink
hotfix/fix-gov-histcont: Fix #5650 - /stocks/gov/histcont (#5676)
Browse files Browse the repository at this point in the history
* fix histcont

* some cleanup

* remove sort line

* 12-31 not 12-12

* columns_keep_types
  • Loading branch information
deeleeramone committed Nov 7, 2023
1 parent aec5c9e commit da3cbb7
Showing 1 changed file with 20 additions and 15 deletions.
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

0 comments on commit da3cbb7

Please sign in to comment.