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

[BugFix] Clean Up Nominal GDP & Add EconDB As Provider #6581

Merged
merged 7 commits into from
Jul 13, 2024
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
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"""Nominal 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
Expand All @@ -16,31 +16,21 @@
class GdpNominalQueryParams(QueryParams):
"""Nominal GDP Query."""

units: Literal["usd", "usd_cap"] = Field(
default="usd",
description=QUERY_DESCRIPTIONS.get("units", "")
+ " Units to get nominal GDP in. Either usd or usd_cap indicating per capita.",
)
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")
)

@field_validator("units", 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 GdpNominalData(Data):
"""Nominal GDP Data."""

date: Optional[dateType] = Field(
default=None, description=DATA_DESCRIPTIONS.get("date")
date: dateType = Field(description=DATA_DESCRIPTIONS.get("date"))
country: str = Field(
default=None, description="The country represented by the GDP value."
)
value: Optional[float] = Field(
default=None, description="Nominal GDP value on the date."
value: Union[int, float] = Field(
description="GDP value for the country and date.",
)
Original file line number Diff line number Diff line change
Expand Up @@ -173,17 +173,20 @@ def test_economy_gdp_forecast(params, headers):
[
(
{
"units": "usd",
"country": "united_states",
"start_date": "2023-01-01",
"end_date": "2023-06-06",
"provider": "oecd",
"provider": "econdb",
"use_cache": False,
}
),
(
{
"country": "united_states",
"provider": "oecd",
"units": "usd",
"units": "level",
"frequency": "quarter",
"price_base": "volume",
"start_date": "2023-01-01",
"end_date": "2023-06-06",
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,23 @@ def test_economy_gdp_forecast(params, obb):
@parametrize(
"params",
[
({"units": "usd", "start_date": "2021-01-01", "end_date": "2023-06-06"}),
(
{
"country": "united_states",
"start_date": "2023-01-01",
"end_date": "2023-06-06",
"provider": "econdb",
"use_cache": False,
}
),
(
{
"country": "united_states",
"provider": "oecd",
"units": "usd",
"start_date": "2021-01-01",
"units": "level",
"price_base": "volume",
"frequency": "quarter",
"start_date": "2023-01-01",
"end_date": "2023-06-06",
}
),
Expand Down
232 changes: 214 additions & 18 deletions openbb_platform/openbb/assets/reference.json
Original file line number Diff line number Diff line change
Expand Up @@ -2637,17 +2637,9 @@
"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=usd, provider='oecd')\n```\n\n",
"parameters": {
"standard": [
{
"name": "units",
"type": "Literal['usd', 'usd_cap']",
"description": "The unit of measurement for the data. Units to get nominal GDP in. Either usd or usd_cap indicating per capita.",
"default": "usd",
"optional": true,
"choices": null
},
{
"name": "start_date",
"type": "Union[date, str]",
Expand All @@ -2666,21 +2658,191 @@
},
{
"name": "provider",
"type": "Literal['oecd']",
"description": "The provider to use, by default None. If None, the priority list configured in the settings is used. Default priority: oecd.",
"type": "Literal['econdb', 'oecd']",
"description": "The provider to use, by default None. If None, the priority list configured in the settings is used. Default priority: econdb, oecd.",
"default": null,
"optional": true
}
],
"oecd": [
"econdb": [
{
"name": "country",
"type": "Literal['australia', 'austria', 'belgium', 'brazil', 'canada', 'chile', 'colombia', 'costa_rica', 'czech_republic', 'denmark', 'estonia', 'euro_area', 'european_union', 'finland', 'france', 'germany', 'greece', 'hungary', 'iceland', 'indonesia', 'ireland', 'israel', 'italy', 'japan', 'korea', 'latvia', 'lithuania', 'luxembourg', 'mexico', 'netherlands', 'new_zealand', 'norway', 'poland', 'portugal', 'russia', 'slovak_republic', 'slovenia', 'south_africa', 'spain', 'sweden', 'switzerland', 'turkey', 'united_kingdom', 'united_states', 'all']",
"description": "Country to get GDP for.",
"type": "Union[str, List[str]]",
"description": "The country to get data.Use 'all' to get data for all available countries. Multiple items allowed for provider(s): econdb, oecd.",
"default": "united_states",
"optional": true,
"choices": [
"oecd",
"oecd_26",
"oecd_europe",
"g7",
"g20",
"euro_area",
"european_union_27",
"european_union_15",
"nafta",
"argentina",
"australia",
"austria",
"belgium",
"bulgaria",
"brazil",
"canada",
"chile",
"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",
"poland",
"portugal",
"romania",
"russia",
"saudi_arabia",
"slovak_republic",
"slovenia",
"south_africa",
"spain",
"sweden",
"switzerland",
"turkey",
"united_kingdom",
"united_states",
"all"
]
},
{
"name": "use_cache",
"type": "bool",
"description": "If True, the request will be cached for one day. Using cache is recommended to avoid needlessly requesting the same data.",
"default": true,
"optional": true,
"choices": null
}
],
"oecd": [
{
"name": "country",
"type": "Union[str, List[str]]",
"description": "The country to get data. Use 'all' to get data for all available countries. Multiple items allowed for provider(s): oecd.",
"default": "united_states",
"optional": true,
"choices": [
"oecd",
"oecd_26",
"oecd_europe",
"g7",
"g20",
"euro_area",
"european_union_27",
"european_union_15",
"nafta",
"argentina",
"australia",
"austria",
"belgium",
"bulgaria",
"brazil",
"canada",
"chile",
"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",
"poland",
"portugal",
"romania",
"russia",
"saudi_arabia",
"slovak_republic",
"slovenia",
"south_africa",
"spain",
"sweden",
"switzerland",
"turkey",
"united_kingdom",
"united_states",
"all"
]
},
{
"name": "frequency",
"type": "Literal['quarter', 'annual']",
"description": "Frequency of the data.",
"default": "quarter",
"optional": true,
"choices": [
"quarter",
"annual"
]
},
{
"name": "units",
"type": "Literal['level', 'index', 'capita']",
"description": "The unit of measurement for the data.Both 'level' and 'capita' (per) are measured in USD.",
"default": "level",
"optional": true,
"choices": [
"level",
"index",
"capita"
]
},
{
"name": "price_base",
"type": "Literal['current_prices', 'volume']",
"description": "Price base for the data, volume is chain linked volume.",
"default": "current_prices",
"optional": true,
"choices": [
"current_prices",
"volume"
]
}
]
},
"returns": {
Expand All @@ -2692,7 +2854,7 @@
},
{
"name": "provider",
"type": "Optional[Literal['oecd']]",
"type": "Optional[Literal['econdb', 'oecd']]",
"description": "Provider name."
},
{
Expand All @@ -2718,16 +2880,50 @@
"name": "date",
"type": "date",
"description": "The date of the data.",
"default": "",
"optional": false,
"choices": null
},
{
"name": "country",
"type": "str",
"description": "The country represented by the GDP value.",
"default": null,
"optional": true,
"choices": null
},
{
"name": "value",
"type": "Union[int, float]",
"description": "GDP value for the country and date.",
"default": "",
"optional": false,
"choices": null
}
],
"econdb": [
{
"name": "value",
"type": "Union[int, float]",
"description": "GDP value for the country and date.",
"default": "",
"optional": false,
"choices": null
},
{
"name": "real_growth_qoq",
"type": "float",
"description": "Nominal GDP value on the date.",
"default": null,
"optional": true,
"description": "Real GDP growth rate quarter over quarter.",
"default": "",
"optional": false,
"choices": null
},
{
"name": "real_growth_yoy",
"type": "float",
"description": "Real GDP growth rate year over year.",
"default": "",
"optional": false,
"choices": null
}
],
Expand Down
Loading
Loading