[BugFix] Fix gdp.forecast (#6585)

* fix gdp.forecast

* docstring

* remove invalid country
This commit is contained in:
Danglewood
2024-07-16 03:45:10 -07:00
committed by GitHub
parent 9be525dd14
commit 869d917323
14 changed files with 448 additions and 315 deletions

View File

@@ -1,9 +1,9 @@
"""Forecast GDP Standard Model."""
from datetime import date as dateType
from typing import Literal, Optional
from typing import Optional, Union
from pydantic import Field, field_validator
from pydantic import Field
from openbb_core.provider.abstract.data import Data
from openbb_core.provider.abstract.query_params import QueryParams
@@ -16,35 +16,19 @@ from openbb_core.provider.utils.descriptions import (
class GdpForecastQueryParams(QueryParams):
"""Forecast GDP Query."""
period: Literal["quarter", "annual"] = Field(
default="annual",
description=QUERY_DESCRIPTIONS.get("period", "")
+ " Units for nominal GDP period. Either quarter or annual.",
)
start_date: Optional[dateType] = Field(
default=None, description=QUERY_DESCRIPTIONS.get("start_date")
)
end_date: Optional[dateType] = Field(
default=None, description=QUERY_DESCRIPTIONS.get("end_date")
)
type: Literal["nominal", "real"] = Field(
default="real",
description="Type of GDP to get forecast of. Either nominal or real.",
)
@field_validator("period", "type", mode="before", check_fields=False)
@classmethod
def to_lower(cls, v: Optional[str]) -> Optional[str]:
"""Convert field to lowercase."""
return v.lower() if v else v
class GdpForecastData(Data):
"""Forecast GDP Data."""
date: Optional[dateType] = Field(
default=None, description=DATA_DESCRIPTIONS.get("date")
)
value: Optional[float] = Field(
default=None, description="Nominal GDP value on the date."
date: dateType = Field(description=DATA_DESCRIPTIONS.get("date"))
country: str = Field(description=DATA_DESCRIPTIONS.get("country"))
value: Union[int, float] = Field(
description="Forecasted GDP value for the country and date."
)

View File

@@ -135,23 +135,14 @@ def test_economy_risk_premium(params, headers):
@parametrize(
"params",
[
(
{
"period": "annual",
"start_date": "2023-01-01",
"end_date": "2025-06-06",
"type": "real",
"provider": "oecd",
}
),
(
{
"country": "united_states",
"provider": "oecd",
"period": "annual",
"start_date": "2023-01-01",
"end_date": "2025-06-06",
"type": "real",
"frequency": "annual",
"start_date": None,
"end_date": None,
"units": "volume",
}
),
],

View File

@@ -126,22 +126,14 @@ def test_economy_risk_premium(params, obb):
@parametrize(
"params",
[
(
{
"period": "annual",
"start_date": "2023-01-01",
"end_date": "2025-06-06",
"type": "real",
}
),
(
{
"country": "united_states",
"provider": "oecd",
"period": "annual",
"start_date": "2023-01-01",
"end_date": "2025-06-06",
"type": "real",
"frequency": "annual",
"start_date": None,
"end_date": None,
"units": "volume",
}
),
],

View File

@@ -20,7 +20,14 @@ router = Router(prefix="/gdp")
model="GdpForecast",
examples=[
APIEx(parameters={"provider": "oecd"}),
APIEx(parameters={"period": "annual", "type": "real", "provider": "oecd"}),
APIEx(
parameters={
"country": "united_states,germany,france",
"frequency": "annual",
"units": "capita",
"provider": "oecd",
}
),
],
)
async def forecast(
@@ -37,7 +44,14 @@ async def forecast(
model="GdpNominal",
examples=[
APIEx(parameters={"provider": "oecd"}),
APIEx(parameters={"units": "usd", "provider": "oecd"}),
APIEx(
parameters={
"units": "capita",
"country": "all",
"frequency": "annual",
"provider": "oecd",
}
),
],
)
async def nominal(

View File

@@ -2525,17 +2525,9 @@
"message": null
},
"description": "Get Forecasted GDP Data.",
"examples": "\nExamples\n--------\n\n```python\nfrom openbb import obb\nobb.economy.gdp.forecast(provider='oecd')\nobb.economy.gdp.forecast(period='annual', type='real', provider='oecd')\n```\n\n",
"examples": "\nExamples\n--------\n\n```python\nfrom openbb import obb\nobb.economy.gdp.forecast(provider='oecd')\nobb.economy.gdp.forecast(country=united_states,germany,france, frequency=annual, units=capita, provider='oecd')\n```\n\n",
"parameters": {
"standard": [
{
"name": "period",
"type": "Literal['quarter', 'annual']",
"description": "Time period of the data to return. Units for nominal GDP period. Either quarter or annual.",
"default": "annual",
"optional": true,
"choices": null
},
{
"name": "start_date",
"type": "Union[date, str]",
@@ -2552,14 +2544,6 @@
"optional": true,
"choices": null
},
{
"name": "type",
"type": "Literal['nominal', 'real']",
"description": "Type of GDP to get forecast of. Either nominal or real.",
"default": "real",
"optional": true,
"choices": null
},
{
"name": "provider",
"type": "Literal['oecd']",
@@ -2571,11 +2555,88 @@
"oecd": [
{
"name": "country",
"type": "Literal['argentina', 'asia', 'australia', 'austria', 'belgium', 'brazil', 'bulgaria', 'canada', 'chile', 'china', 'colombia', 'costa_rica', 'croatia', 'czech_republic', 'denmark', 'estonia', 'euro_area_17', 'finland', 'france', 'germany', 'greece', 'hungary', 'iceland', 'india', 'indonesia', 'ireland', 'israel', 'italy', 'japan', 'korea', 'latvia', 'lithuania', 'luxembourg', 'mexico', 'netherlands', 'new_zealand', 'non-oecd', 'norway', 'oecd_total', 'peru', 'poland', 'portugal', 'romania', 'russia', 'slovak_republic', 'slovenia', 'south_africa', 'spain', 'sweden', 'switzerland', 'turkey', 'united_kingdom', 'united_states', 'world']",
"description": "Country to get GDP for.",
"default": "united_states",
"type": "Union[str, List[str]]",
"description": "Country, or countries, to get forward GDP projections for. Default is all. Multiple items allowed for provider(s): oecd.",
"default": "all",
"optional": true,
"choices": [
"argentina",
"asia",
"australia",
"austria",
"belgium",
"brazil",
"bulgaria",
"canada",
"chile",
"china",
"colombia",
"costa_rica",
"croatia",
"czech_republic",
"denmark",
"estonia",
"finland",
"france",
"germany",
"greece",
"hungary",
"iceland",
"india",
"indonesia",
"ireland",
"israel",
"italy",
"japan",
"korea",
"latvia",
"lithuania",
"luxembourg",
"mexico",
"netherlands",
"new_zealand",
"norway",
"peru",
"poland",
"portugal",
"romania",
"russia",
"slovak_republic",
"slovenia",
"south_africa",
"spain",
"sweden",
"switzerland",
"turkey",
"united_kingdom",
"united_states",
"other_major_oil_producers",
"rest_of_the_world",
"world",
"all"
]
},
{
"name": "frequency",
"type": "Literal['annual', 'quarter']",
"description": "Frequency of the data, default is annual.",
"default": "annual",
"optional": true,
"choices": null
},
{
"name": "units",
"type": "Literal['current_prices', 'volume', 'capita', 'growth', 'deflator']",
"description": "Units of the data, default is volume (chain linked volume, 2015). 'current_prices', 'volume', and 'capita' are expressed in USD; 'growth' as a percent; 'deflator' as an index.",
"default": "volume",
"optional": true,
"choices": [
"current_prices",
"volume",
"capita",
"growth",
"deflator"
]
}
]
},
@@ -2614,16 +2675,24 @@
"name": "date",
"type": "date",
"description": "The date of the data.",
"default": null,
"optional": true,
"default": "",
"optional": false,
"choices": null
},
{
"name": "country",
"type": "str",
"description": "None",
"default": "",
"optional": false,
"choices": null
},
{
"name": "value",
"type": "float",
"description": "Nominal GDP value on the date.",
"default": null,
"optional": true,
"type": "Union[int, float]",
"description": "Forecasted GDP value for the country and date.",
"default": "",
"optional": false,
"choices": null
}
],
@@ -2637,7 +2706,7 @@
"message": null
},
"description": "Get Nominal GDP Data.",
"examples": "\nExamples\n--------\n\n```python\nfrom openbb import obb\nobb.economy.gdp.nominal(provider='oecd')\nobb.economy.gdp.nominal(units=usd, provider='oecd')\n```\n\n",
"examples": "\nExamples\n--------\n\n```python\nfrom openbb import obb\nobb.economy.gdp.nominal(provider='oecd')\nobb.economy.gdp.nominal(units=capita, country=all, frequency=annual, provider='oecd')\n```\n\n",
"parameters": {
"standard": [
{

View File

@@ -25,12 +25,6 @@ class ROUTER_economy_gdp(Container):
@validate
def forecast(
self,
period: Annotated[
Literal["quarter", "annual"],
OpenBBField(
description="Time period of the data to return. Units for nominal GDP period. Either quarter or annual."
),
] = "annual",
start_date: Annotated[
Union[datetime.date, None, str],
OpenBBField(description="Start date of the data, in YYYY-MM-DD format."),
@@ -39,12 +33,6 @@ class ROUTER_economy_gdp(Container):
Union[datetime.date, None, str],
OpenBBField(description="End date of the data, in YYYY-MM-DD format."),
] = None,
type: Annotated[
Literal["nominal", "real"],
OpenBBField(
description="Type of GDP to get forecast of. Either nominal or real."
),
] = "real",
provider: Annotated[
Optional[Literal["oecd"]],
OpenBBField(
@@ -57,18 +45,19 @@ class ROUTER_economy_gdp(Container):
Parameters
----------
period : Literal['quarter', 'annual']
Time period of the data to return. Units for nominal GDP period. Either quarter or annual.
start_date : Union[datetime.date, None, str]
Start date of the data, in YYYY-MM-DD format.
end_date : Union[datetime.date, None, str]
End date of the data, in YYYY-MM-DD format.
type : Literal['nominal', 'real']
Type of GDP to get forecast of. Either nominal or real.
provider : Optional[Literal['oecd']]
The provider to use, by default None. If None, the priority list configured in the settings is used. Default priority: oecd.
country : Literal['argentina', 'asia', 'australia', 'austria', 'belgium', 'brazil', 'bulgaria', 'canada', 'chile', 'china', 'colombia', 'costa_rica', 'croatia', 'czech_republic', 'denmark', 'estonia', 'euro_area_17', 'finland', 'france', 'germany', 'greece', 'hungary', 'iceland', 'india', 'indonesia', 'ireland', 'israel', 'italy', 'japan', 'korea', 'latvia', 'lithuania', 'luxembourg', 'mexico', 'netherlands', 'new_zealand', 'non-oecd', 'norway', 'oecd_total', 'peru', 'poland', 'portugal', 'romania', 'russia', 'slovak_republic', 'slovenia', 'south_africa', 'spain', 'sweden', 'switzerland', 'turkey', 'united_kingdom', 'united_states', 'world']
Country to get GDP for. (provider: oecd)
country : str
Country, or countries, to get forward GDP projections for. Default is all. Multiple comma separated items allowed. (provider: oecd)
frequency : Literal['annual', 'quarter']
Frequency of the data, default is annual. (provider: oecd)
units : Literal['current_prices', 'volume', 'capita', 'growth', 'deflator']
Units of the data, default is volume (chain linked volume, 2015).
'current_prices', 'volume', and 'capita' are expressed in USD; 'growth' as a percent; 'deflator' as an index. (provider: oecd)
Returns
-------
@@ -86,16 +75,18 @@ class ROUTER_economy_gdp(Container):
GdpForecast
-----------
date : Optional[date]
date : date
The date of the data.
value : Optional[float]
Nominal GDP value on the date.
country : str
None
value : Union[int, float]
Forecasted GDP value for the country and date.
Examples
--------
>>> from openbb import obb
>>> obb.economy.gdp.forecast(provider='oecd')
>>> obb.economy.gdp.forecast(period='annual', type='real', provider='oecd')
>>> obb.economy.gdp.forecast(country='united_states,germany,france', frequency='annual', units='capita', provider='oecd')
""" # noqa: E501
return self._run(
@@ -109,12 +100,11 @@ class ROUTER_economy_gdp(Container):
)
},
standard_params={
"period": period,
"start_date": start_date,
"end_date": end_date,
"type": type,
},
extra_params=kwargs,
info={"country": {"oecd": {"multiple_items_allowed": True}}},
)
)
@@ -190,7 +180,7 @@ class ROUTER_economy_gdp(Container):
--------
>>> from openbb import obb
>>> obb.economy.gdp.nominal(provider='oecd')
>>> obb.economy.gdp.nominal(units='usd', provider='oecd')
>>> obb.economy.gdp.nominal(units='capita', country='all', frequency='annual', provider='oecd')
""" # noqa: E501
return self._run(

View File

@@ -1,7 +1,10 @@
"""OECD Forecast GDP Model."""
from datetime import date
from typing import Any, Dict, List, Literal, Optional, Union
# pylint: disable=unused-argument
from datetime import datetime
from typing import Any, Dict, List, Literal, Optional
from warnings import warn
from openbb_core.app.model.abstract.error import OpenBBError
from openbb_core.provider.abstract.fetcher import Fetcher
@@ -9,107 +12,239 @@ from openbb_core.provider.standard_models.gdp_forecast import (
GdpForecastData,
GdpForecastQueryParams,
)
from openbb_oecd.utils import constants
from pydantic import Field, field_validator
from openbb_core.provider.utils.errors import EmptyDataError
from openbb_oecd.utils.constants import (
CODE_TO_COUNTRY_GDP_FORECAST,
COUNTRY_TO_CODE_GDP_FORECAST,
)
from pydantic import Field
gdp_countries = tuple(constants.COUNTRY_TO_CODE_GDP_FORECAST.keys())
GDPCountriesLiteral = Literal[gdp_countries] # type: ignore
COUNTRIES = list(COUNTRY_TO_CODE_GDP_FORECAST) + ["all"]
# pylint: disable=unused-argument
COUNTRIES_QUARTER = [
"australia",
"austria",
"belgium",
"canada",
"chile",
"colombia",
"costa_rica",
"czechia",
"denmark",
"estonia",
"finland",
"france",
"germany",
"greece",
"iceland",
"ireland",
"israel",
"italy",
"japan",
"korea",
"lithuania",
"luxembourg",
"netherlands",
"new_zealand",
"norway",
"poland",
"portugal",
"slovak_republic",
"spain",
"sweden",
"switzerland",
"turkey",
"united_kingdom",
"united_states",
]
class OECDGdpForecastQueryParams(GdpForecastQueryParams):
"""OECD GDP Forecast Query."""
"""OECD GDP Forecast Query.
country: GDPCountriesLiteral = Field(
description="Country to get GDP for.", default="united_states"
The OECD Economic Outlook presents the OECD's analysis of the major
global economic trends and prospects for the next two years.
The Outlook puts forward a consistent set of projections for output, employment, government spending,
prices and current balances based on a review of each member country
and of the induced effect on each of them on international developments.
https://www.oecd.org/economic-outlook/
"""
__json_schema_extra__ = {
"country": {"multiple_items_allowed": True},
}
country: str = Field(
description="Country, or countries, to get forward GDP projections for. Default is all.",
default="all",
json_schema_extra={"choices": COUNTRIES}, # type: ignore
)
frequency: Literal["annual", "quarter"] = Field(
default="annual",
description="Frequency of the data, default is annual.",
)
units: Literal["current_prices", "volume", "capita", "growth", "deflator"] = Field(
default="volume",
description="Units of the data, default is volume (chain linked volume, 2015)."
+ "\n'current_prices', 'volume', and 'capita' are expressed in USD; 'growth' as a percent;"
+ " 'deflator' as an index.",
json_schema_extra={
"choices": ["current_prices", "volume", "capita", "growth", "deflator"]
},
)
class OECDGdpForecastData(GdpForecastData):
"""OECD GDP Forecast Data."""
@field_validator("date", mode="before")
@classmethod
def date_validate(
cls, in_date: Union[date, Union[str, int]]
): # pylint: disable=E0213
"""Validate date."""
# pylint: disable=import-outside-toplevel
import re
# OECD Returns dates like 2022-Q2, so we map that to the end of the quarter.
if isinstance(in_date, str):
if re.match(r"\d{4}-Q[1-4]$", in_date):
year, quarter = in_date.split("-")
quarter_int = int(quarter[1])
month = quarter_int * 3
return date(int(year), month, 1)
raise OpenBBError("Date string does not match the format YYYY-QN")
if isinstance(in_date, int):
return date(in_date, 12, 31)
return date
class OECDGdpForecastFetcher(
Fetcher[OECDGdpForecastQueryParams, List[OECDGdpForecastData]]
):
"""Transform the query, extract and transform the data from the OECD endpoints."""
"""OECD GDP Forecast Fetcher."""
@staticmethod
def transform_query(params: Dict[str, Any]) -> OECDGdpForecastQueryParams:
"""Transform the query."""
transformed_params = params.copy()
if transformed_params["start_date"] is None:
transformed_params["start_date"] = date(1990, 1, 1)
if transformed_params["end_date"] is None:
transformed_params["end_date"] = date(date.today().year + 10, 12, 31)
countries = transformed_params.get("country")
new_countries: List = []
freq = transformed_params.get("frequency")
if not countries:
new_countries.append("all")
if countries:
countries = (
countries.split(",") if isinstance(countries, str) else countries
)
if "all" in countries:
new_countries = ["all"]
else:
for country in countries:
if freq == "quarter":
if country.lower() in COUNTRIES_QUARTER:
new_countries.append(country.lower())
else:
warn(f"{country} is not available for quarterly data.")
else: # noqa
if country.lower() in COUNTRIES:
new_countries.append(country.lower())
else:
warn(f"{country} is not available for annual data.")
if not new_countries:
raise OpenBBError(
"No valid countries were found for the supplied parameters."
)
transformed_params["country"] = ",".join(new_countries)
if not transformed_params.get("start_date"):
transformed_params["start_date"] = datetime(
datetime.today().year, 1, 1
).date()
if not transformed_params.get("end_date"):
transformed_params["end_date"] = datetime(
datetime.today().year + 2, 12, 31
).date()
return OECDGdpForecastQueryParams(**transformed_params)
@staticmethod
def extract_data(
async def aextract_data(
query: OECDGdpForecastQueryParams,
credentials: Optional[Dict[str, str]],
**kwargs: Any,
) -> List[Dict]:
"""Return the raw data from the OECD endpoint."""
# pylint: disable=import-outside-toplevel
from openbb_oecd.utils import helpers
from io import StringIO # noqa
from openbb_oecd.utils.helpers import oecd_date_to_python_date
from pandas import read_csv
from openbb_core.provider.utils.helpers import amake_request
units = query.period[0].upper()
_type = "REAL" if query.type == "real" else "NOM"
freq = "Q" if query.frequency == "quarter" else "A"
measure_dict = {
"current_prices": "GDP_USD", # This gives questionable results.
"volume": "GDPV_USD",
"capita": "GDPVD_CAP",
"growth": "GDPV_ANNPCT",
"deflator": "PGDP",
}
measure = measure_dict[query.units] # type: ignore
if query.units == "capita" and freq == "Q":
warn(
"Capita data is not available for quarterly data, using annual data instead."
)
freq = "A"
def country_string(input_str: str):
"""Convert the list of countries to an abbreviated string."""
if input_str == "all":
return ""
_countries = input_str.split(",")
return "+".join(
[
COUNTRY_TO_CODE_GDP_FORECAST[country.lower()]
for country in _countries
]
)
country = country_string(query.country)
base_url = "https://stats.oecd.org/sdmx-json/data/DP_LIVE"
url = (
f"{base_url}/.{_type}GDPFORECAST.TOT.AGRWTH.{units}"
"/OECD?contentType=csv&detail=code&separator=comma&csv-lang=en"
f"&startPeriod={query.start_date}&endPeriod={query.end_date}"
"https://sdmx.oecd.org/public/rest/data/OECD.ECO.MAD,DSD_EO@DF_EO,1.1"
+ f"/{country}.{measure}.{freq}?"
+ f"startPeriod={query.start_date}&endPeriod={query.end_date}"
+ "&dimensionAtObservation=TIME_PERIOD&detail=dataonly&format=csvfile"
)
data_df = helpers.fetch_data(url, csv_kwargs={"encoding": "utf-8"}, **kwargs)
# Sometimes there is weird unicode characters in the column names, so we need to rename them.
# Even changing the encoding on the fetch doesn't seem to help.
data_df = data_df.rename(
columns={
"LOCATION": "country",
"TIME_PERIOD": "date",
"OBS_VALUE": "value",
"Location": "country",
}
async def response_callback(response, _):
"""Response callback."""
if response.status != 200:
raise OpenBBError(f"Error with the OECD request: {response.status}")
return await response.text()
headers = {"Accept": "application/vnd.sdmx.data+csv; charset=utf-8"}
response = await amake_request(
url, timeout=30, headers=headers, response_callback=response_callback
)
data_df["country"] = data_df["country"].map(
constants.CODE_TO_COUNTRY_GDP_FORECAST
df = read_csv(StringIO(response)).get( # type: ignore
["REF_AREA", "TIME_PERIOD", "OBS_VALUE"]
)
data_df = data_df[data_df["country"] == query.country]
data_df = data_df[["country", "date", "value"]]
data_df["date"] = data_df["date"].apply(helpers.oecd_date_to_python_date)
data_df = data_df[
(data_df["date"] <= query.end_date) & (data_df["date"] >= query.start_date)
if df.empty: # type: ignore
raise EmptyDataError("No data was found.")
df = df.rename( # type: ignore
columns={"REF_AREA": "country", "TIME_PERIOD": "date", "OBS_VALUE": "value"}
)
df.country = [
(
CODE_TO_COUNTRY_GDP_FORECAST.get(d, d)
.replace("_", " ")
.replace("asia", "Dynamic Asian Economies")
.title()
)
for d in df.country
]
data_df["date"] = data_df["date"].apply(
lambda x: x.year
) # Validator won't accept datetime.date?
return data_df.to_dict(orient="records")
df.date = df.date.apply(oecd_date_to_python_date)
df = df[df["value"].notnull()]
if query.units != "growth":
df["value"] = df.value.astype("int64")
df = df[df["value"] > 0]
if query.units == "growth":
df["value"] = df.value.astype("float64") / 100
df = df[df["value"] > 0]
df = df.sort_values(by=["date", "value"], ascending=[True, False])
return df.to_dict(orient="records")
@staticmethod
def transform_data(

View File

@@ -186,7 +186,7 @@ class OECDGdpNominalFetcher(
if query.units == "level":
df["value"] = (df["value"].astype(float) * 1_000_000).astype("int64")
df = df.sort_values(by=["date", "value"], ascending=False)
df = df.sort_values(by=["date", "value"], ascending=[True, False])
return df.replace({nan: None}).to_dict(orient="records")

View File

@@ -140,7 +140,6 @@ COUNTRY_TO_CODE_GDP_FORECAST = {
"czech_republic": "CZE",
"denmark": "DNK",
"estonia": "EST",
"euro_area_17": "EA17",
"finland": "FIN",
"france": "FRA",
"germany": "DEU",
@@ -160,9 +159,7 @@ COUNTRY_TO_CODE_GDP_FORECAST = {
"mexico": "MEX",
"netherlands": "NLD",
"new_zealand": "NZL",
"non-oecd": "NMEC",
"norway": "NOR",
"oecd_total": "OECD",
"peru": "PER",
"poland": "POL",
"portugal": "PRT",
@@ -177,7 +174,9 @@ COUNTRY_TO_CODE_GDP_FORECAST = {
"turkey": "TUR",
"united_kingdom": "GBR",
"united_states": "USA",
"world": "WLD",
"other_major_oil_producers": "OIL_O",
"rest_of_the_world": "WXD",
"world": "W",
}
CODE_TO_COUNTRY_GDP_FORECAST = {v: k for k, v in COUNTRY_TO_CODE_GDP_FORECAST.items()}

View File

@@ -1,98 +0,0 @@
interactions:
- request:
body: null
headers:
Accept:
- '*/*'
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
method: GET
uri: https://stats.oecd.org/sdmx-json/data/DP_LIVE/.REALGDPFORECAST.TOT.AGRWTH.A/OECD?contentType=csv&csv-lang=en&detail=code&endPeriod=2023-06-06&separator=comma&startPeriod=2020-01-01
response:
body:
string: !!binary |
H4sIAAAAAAAEAO29B2AcSZYlJi9tynt/SvVK1+B0oQiAYBMk2JBAEOzBiM3mkuwdaUcjKasqgcpl
VmVdZhZ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/AI5BaGhoKwAA
headers:
Access-Control-Allow-Headers:
- Content-Type
Access-Control-Allow-Methods:
- POST,GET,OPTIONS
Access-Control-Allow-Origin:
- '*'
Cache-Control:
- private
Content-Disposition:
- attachment;filename=DP_LIVE_01072024211332615.csv
Content-Encoding:
- gzip
Content-Type:
- text/csv
Date:
- Mon, 01 Jul 2024 19:13:32 GMT
Transfer-Encoding:
- chunked
Vary:
- Accept-Encoding
status:
code: 200
message: OK
version: 1

View File

@@ -0,0 +1,48 @@
interactions:
- request:
body: null
headers:
Accept:
- application/vnd.sdmx.data+csv; charset=utf-8
method: GET
uri: https://sdmx.oecd.org/public/rest/data/OECD.ECO.MAD,DSD_EO@DF_EO,1.1/USA.GDPV_USD.A?detail=dataonly&dimensionAtObservation=TIME_PERIOD&endPeriod=2024-01-01&format=csvfile&startPeriod=2023-01-01
response:
body:
string: !!binary |
H4sIAAAAAAAEAO29B2AcSZYlJi9tynt/SvVK1+B0oQiAYBMk2JBAEOzBiM3mkuwdaUcjKasqgcpl
VmVdZhZAzO2dvPfee++999577733ujudTif33/8/XGZkAWz2zkrayZ4hgKrIHz9+fB8/Ip4evzl+
9vzL745enT77/Y9fnR6Pvjg9fv3Vq9PRs1enPzF6c/bF6e//8vTV2ZdPR18+ef37/+Tx869O+bfX
b47ffPV69NWLsze/v3lF/vjq+ZvRyVevXp2+OPl9Rk+OXzMAAvvm218+/fL5l5//PqOnpydnXxw/
fz16+ers5PT3R5vR8dPvfPX6zRenL978xsmXpydPx6cnX46/OH766Onrp7//6Ze/59Nn9O/W7nj3
zuir18ejz5++/Mnf/6vXT0fHo72dvXujvd0HD+4/vL9z79Pde7v3Rub5jZP/B2ir18HhAAAA
headers:
Accept-Ranges:
- values
Cache-Control:
- no-store,no-cache
Content-Disposition:
- attachment; filename="OECD.ECO.MAD,DSD_EO@DF_EO,1.1+USA.GDPV_USD.A.csv"
Content-Encoding:
- gzip
Content-Language:
- en,en-US
Content-Type:
- application/vnd.sdmx.data+csv; charset=utf-8
Date:
- Sat, 13 Jul 2024 18:48:17 GMT
Pragma:
- no-cache
Strict-Transport-Security:
- max-age=2592000
Transfer-Encoding:
- chunked
Vary:
- Accept,Accept-Encoding,Accept-Encoding
X-Server-Node:
- Server 2
api-supported-versions:
- '1'
status:
code: 200
message: OK
version: 1

View File

@@ -0,0 +1,48 @@
interactions:
- request:
body: null
headers:
Accept:
- application/vnd.sdmx.data+csv; charset=utf-8
method: GET
uri: https://sdmx.oecd.org/public/rest/data/OECD.ECO.MAD,DSD_EO@DF_EO,1.1/USA.GDPV_USD.A?detail=dataonly&dimensionAtObservation=TIME_PERIOD&endPeriod=2024-01-01&format=csvfile&startPeriod=2023-01-01
response:
body:
string: !!binary |
H4sIAAAAAAAEAO29B2AcSZYlJi9tynt/SvVK1+B0oQiAYBMk2JBAEOzBiM3mkuwdaUcjKasqgcpl
VmVdZhZAzO2dvPfee++999577733ujudTif33/8/XGZkAWz2zkrayZ4hgKrIHz9+fB8/Ip4evzl+
9vzL745enT77/Y9fnR6Pvjg9fv3Vq9PRs1enPzF6c/bF6e//8vTV2ZdPR18+ef37/+Tx869O+bfX
b47ffPV69NWLsze/v3lF/vjq+ZvRyVevXp2+OPl9Rk+OXzMAAvvm218+/fL5l5//PqOnpydnXxw/
fz16+ers5PT3R5vR8dPvfPX6zRenL978xsmXpydPx6cnX46/OH766Onrp7//6Ze/59Nn9O/W7nj3
zuir18ejz5++/Mnf/6vXT0fHo72dvXujvd0HD+4/vL9z79Pde7v3Rub5jZP/B2ir18HhAAAA
headers:
Accept-Ranges:
- values
Cache-Control:
- no-store,no-cache
Content-Disposition:
- attachment; filename="OECD.ECO.MAD,DSD_EO@DF_EO,1.1+USA.GDPV_USD.A.csv"
Content-Encoding:
- gzip
Content-Language:
- en,en-US
Content-Type:
- application/vnd.sdmx.data+csv; charset=utf-8
Date:
- Sat, 13 Jul 2024 18:47:04 GMT
Pragma:
- no-cache
Strict-Transport-Security:
- max-age=2592000
Transfer-Encoding:
- chunked
Vary:
- Accept,Accept-Encoding,Accept-Encoding
X-Server-Node:
- Server 2
api-supported-versions:
- '1'
status:
code: 200
message: OK
version: 1

View File

@@ -4,7 +4,9 @@ import datetime
import pytest
from openbb_core.app.service.user_service import UserService
from openbb_oecd.models.composite_leading_indicator import OECDCompositeLeadingIndicatorFetcher
from openbb_oecd.models.composite_leading_indicator import (
OECDCompositeLeadingIndicatorFetcher,
)
from openbb_oecd.models.consumer_price_index import OECDCPIFetcher
from openbb_oecd.models.gdp_forecast import OECDGdpForecastFetcher
from openbb_oecd.models.gdp_nominal import OECDGdpNominalFetcher
@@ -72,13 +74,13 @@ def test_oecd_real_gdp_fetcher(credentials=test_credentials):
assert result is None
@pytest.mark.skip(reason="Downloads a huge file, code needs to be fixed to use params.")
@pytest.mark.record_http
def test_oecd_forecast_gdp_fetcher(credentials=test_credentials):
def test_oecd_gdp_forecast_fetcher(credentials=test_credentials):
"""Test the OECD GDP Forecast fetcher."""
params = {
"start_date": datetime.date(2020, 1, 1),
"end_date": datetime.date(2023, 6, 6),
"country": "united_states",
"start_date": datetime.date(2023, 1, 1),
"end_date": datetime.date(2024, 1, 1),
}
fetcher = OECDGdpForecastFetcher()