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

Fix Bugs #3433

Merged
merged 7 commits into from
Nov 17, 2022
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions openbb_terminal/alternative/covid/covid_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ def call_country(self, other_args: List[str]):
)
return
country = ns_parser.country.title().replace("_", " ")
if country == "Us":
country = "US"
self.country = country
console.print(f"[cyan]{country}[/cyan] loaded\n")
else:
Expand Down
10 changes: 10 additions & 0 deletions openbb_terminal/alternative/covid/covid_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ def get_global_cases(country: str) -> pd.DataFrame:
.T
)
cases.index = pd.to_datetime(cases.index)
if country not in cases:
console.print("[red]The selection `{country}` is not a valid option.[/red]\n")
return pd.DataFrame()
cases = pd.DataFrame(cases[country]).diff().dropna()
if cases.shape[1] > 1:
return pd.DataFrame(cases.sum(axis=1))
Expand Down Expand Up @@ -89,6 +92,9 @@ def get_global_deaths(country: str) -> pd.DataFrame:
.T
)
deaths.index = pd.to_datetime(deaths.index)
if country not in deaths:
console.print("[red]The selection `{country}` is not a valid option.[/red]\n")
return pd.DataFrame()
deaths = pd.DataFrame(deaths[country]).diff().dropna()
if deaths.shape[1] > 1:
return pd.DataFrame(deaths.sum(axis=1))
Expand All @@ -114,8 +120,12 @@ def get_covid_ov(
pd.DataFrame
Dataframe of historical cases and deaths
"""
if country.lower() == "us":
country = "US"
cases = get_global_cases(country)
deaths = get_global_deaths(country)
if cases.empty or deaths.empty:
return pd.DataFrame()
data = pd.concat([cases, deaths], axis=1)
data.columns = ["Cases", "Deaths"]
data.index = [x.strftime("%Y-%m-%d") for x in data.index]
Expand Down
4 changes: 4 additions & 0 deletions openbb_terminal/alternative/covid/covid_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ def plot_covid_ov(
"""
cases = covid_model.get_global_cases(country) / 1_000
deaths = covid_model.get_global_deaths(country)
if cases.empty or deaths.empty:
return
ov = pd.concat([cases, deaths], axis=1)
ov.columns = ["Cases", "Deaths"]

Expand Down Expand Up @@ -148,6 +150,8 @@ def display_covid_ov(
plot: bool
Flag to display historical plot
"""
if country.lower() == "us":
country = "US"
if plot:
plot_covid_ov(country)
if raw:
Expand Down