Skip to content

Commit

Permalink
returning always a dataframe
Browse files Browse the repository at this point in the history
  • Loading branch information
hjoaquim committed Jan 27, 2023
1 parent df50b4f commit d5dbf31
Show file tree
Hide file tree
Showing 8 changed files with 4,371 additions and 3 deletions.
6 changes: 3 additions & 3 deletions openbb_terminal/economy/fred_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,13 @@ def get_series_ids(search_query: str, limit: int = -1) -> pd.DataFrame:
console.print("[red]Invalid API Key[/red]\n")
else:
console.print(d_series["error_message"])
return [], []
return pd.DataFrame()

if "seriess" not in d_series:
return [], []
return pd.DataFrame()

if not d_series["seriess"]:
return [], []
return pd.DataFrame()

df_series = pd.DataFrame(d_series["seriess"])
df_series = df_series.sort_values(by=["popularity"], ascending=False)
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
interactions:
- request:
body: null
headers:
Accept:
- '*/*'
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
method: GET
uri: https://api.stlouisfed.org/fred/series/search?api_key=MOCK_API_KEY&file_type=json&search_text=xyz
response:
body:
string: !!binary |
H4sIAAAAAAAEA6pWKkpNzCnJzE2NLy5JLCpRslIyMjAy1jUw1DUyV9JByKbmpaDL5RelpBbFJ1Uq
WSkVpyYWJWfEFyXmZSvpKBXnF5XEg2WVrJRSUouTlXSUkvNL80qUrAx0lPLT0opTIUzAcjJzM0uU
rAwNDAx0lIpTizJTi4uVrKJjawGUcQg+lwAAAA==
headers:
Accept-Ranges:
- bytes
Connection:
- keep-alive
Content-Encoding:
- gzip
Content-Length:
- '142'
Content-Type:
- application/json; charset=UTF-8
Date:
- Fri, 27 Jan 2023 16:52:25 GMT
ETag:
- '"f251e9d2283cd8abcc87903c2a4b40fb-gzip"'
Expires:
- Fri, 27 Jan 2023 17:02:25 GMT
Vary:
- Accept-Encoding
x-rate-limit-limit:
- '120'
x-rate-limit-remaining:
- '118'
status:
code: 200
message: OK
version: 1

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
""
17 changes: 17 additions & 0 deletions tests/openbb_terminal/economy/test_fred_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

# IMPORTATION THIRDPARTY
import pytest
import pandas as pd

# IMPORTATION INTERNAL
from openbb_terminal.economy import fred_model
Expand Down Expand Up @@ -108,3 +109,19 @@ def test_yield_curve_none(date, recorder):
assert returned_date.strftime("%Y-%m-%d") == "2022-03-21"
assert not result_df.empty
recorder.capture(result_df)


@pytest.mark.vcr
@pytest.mark.parametrize(
"func, kwargs_dict",
[
("get_series_ids", {"search_query": "unemployment rate"}),
("get_series_ids", {"search_query": "gdp"}),
("get_series_ids", {"search_query": "xyz"}),
],
)
def test_get_series_ids(func, kwargs_dict, recorder):
result_df = getattr(fred_model, func)(**kwargs_dict)

assert isinstance(result_df, pd.DataFrame)
recorder.capture(result_df)

0 comments on commit d5dbf31

Please sign in to comment.