From 8877f616988e68f470b7c96df300c30607c49f03 Mon Sep 17 00:00:00 2001 From: Danglewood <85772166+deeleeramone@users.noreply.github.com> Date: Thu, 4 Jul 2024 02:39:31 -0700 Subject: [BugFix] Fix OECD Unemployment Age Brackets & Fix `No module named 'pkg_resources'` (#6563) * fix pkg_resources not in Python 3.9 * black --- openbb_platform/core/openbb_core/app/version.py | 20 ++++++++++--------- openbb_platform/openbb/assets/reference.json | 23 +++++++++++++--------- openbb_platform/openbb/package/economy.py | 2 +- .../oecd/openbb_oecd/models/unemployment.py | 19 +++++------------- 4 files changed, 31 insertions(+), 33 deletions(-) diff --git a/openbb_platform/core/openbb_core/app/version.py b/openbb_platform/core/openbb_core/app/version.py index 39872d98a1c..c49232ed6e6 100644 --- a/openbb_platform/core/openbb_core/app/version.py +++ b/openbb_platform/core/openbb_core/app/version.py @@ -2,10 +2,12 @@ import shutil import subprocess +from importlib.metadata import ( + PackageNotFoundError, + version as pkg_version, +) from pathlib import Path -import pkg_resources - PACKAGE = "openbb" @@ -13,15 +15,15 @@ def get_package_version(package: str): """Retrieve the version of a package from installed pip packages.""" is_nightly = False try: - version = pkg_resources.get_distribution(package).version - except pkg_resources.DistributionNotFound: + version = pkg_version(package) + except PackageNotFoundError: package += "-nightly" is_nightly = True try: - version = pkg_resources.get_distribution(package).version - except pkg_resources.DistributionNotFound: + version = pkg_version(package) + except PackageNotFoundError: package = "openbb-core" - version = pkg_resources.get_distribution(package).version + version = pkg_version(package) version += "core" if is_git_repo(Path(__file__).parent.resolve()) and not is_nightly: @@ -56,10 +58,10 @@ def get_major_minor(version: str) -> tuple[int, int]: try: VERSION = get_package_version(PACKAGE) -except pkg_resources.DistributionNotFound: +except PackageNotFoundError: VERSION = "unknown" try: CORE_VERSION = get_package_version("openbb-core") -except pkg_resources.DistributionNotFound: +except PackageNotFoundError: CORE_VERSION = "unknown" diff --git a/openbb_platform/openbb/assets/reference.json b/openbb_platform/openbb/assets/reference.json index 9139dd5420c..28947a0e598 100644 --- a/openbb_platform/openbb/assets/reference.json +++ b/openbb_platform/openbb/assets/reference.json @@ -3,7 +3,7 @@ "info": { "title": "OpenBB Platform (Python)", "description": "Investment research for everyone, anywhere.", - "core": "1.2.7", + "core": "1.2.9", "extensions": { "openbb_core_extension": [ "commodity@1.1.3", @@ -2443,8 +2443,8 @@ }, { "name": "date", - "type": "Union[date, str]", - "description": "A specific date to get data for.", + "type": "Union[Union[Union[str, date], str], List[Union[Union[str, date], str]]]", + "description": "A specific date to get data for. Multiple items allowed for provider(s): yfinance.", "default": null, "optional": true, "choices": null @@ -2490,6 +2490,14 @@ }, "data": { "standard": [ + { + "name": "date", + "type": "date", + "description": "The date of the data.", + "default": null, + "optional": true, + "choices": null + }, { "name": "expiration", "type": "str", @@ -2501,7 +2509,7 @@ { "name": "price", "type": "float", - "description": "The close price.", + "description": "The price of the futures contract.", "default": null, "optional": true, "choices": null @@ -5374,17 +5382,14 @@ }, { "name": "age", - "type": "Literal['total', '15-24', '25-54', '55-64', '15-64', '15-74']", + "type": "Literal['total', '15-24', '25+']", "description": "Age group to get unemployment for. Total indicates 15 years or over", "default": "total", "optional": true, "choices": [ "total", "15-24", - "25-54", - "55-64", - "15-64", - "15-74" + "25+" ] }, { diff --git a/openbb_platform/openbb/package/economy.py b/openbb_platform/openbb/package/economy.py index e6719909149..65befb797d2 100644 --- a/openbb_platform/openbb/package/economy.py +++ b/openbb_platform/openbb/package/economy.py @@ -2187,7 +2187,7 @@ class ROUTER_economy(Container): The provider to use, by default None. If None, the priority list configured in the settings is used. Default priority: oecd. sex : Literal['total', 'male', 'female'] Sex to get unemployment for. (provider: oecd) - age : Literal['total', '15-24', '25-54', '55-64', '15-64', '15-74'] + age : Literal['total', '15-24', '25+'] Age group to get unemployment for. Total indicates 15 years or over (provider: oecd) seasonal_adjustment : bool Whether to get seasonally adjusted unemployment. Defaults to False. (provider: oecd) diff --git a/openbb_platform/providers/oecd/openbb_oecd/models/unemployment.py b/openbb_platform/providers/oecd/openbb_oecd/models/unemployment.py index 236513430d2..5641c967188 100644 --- a/openbb_platform/providers/oecd/openbb_oecd/models/unemployment.py +++ b/openbb_platform/providers/oecd/openbb_oecd/models/unemployment.py @@ -29,18 +29,12 @@ CountriesList = sorted(list(countries)) # type: ignore AGES = [ "total", "15-24", - "25-54", - "55-64", - "15-64", - "15-74", + "25+", ] AgesLiteral = Literal[ "total", "15-24", - "25-54", - "55-64", - "15-64", - "15-74", + "25+", ] @@ -55,7 +49,7 @@ class OECDUnemploymentQueryParams(UnemploymentQueryParams): country: str = Field( description=QUERY_DESCRIPTIONS.get("country", ""), default="united_states", - choices=CountriesList, + json_schema_extra={"choices": CountriesList}, # type: ignore ) sex: Literal["total", "male", "female"] = Field( description="Sex to get unemployment for.", @@ -65,7 +59,7 @@ class OECDUnemploymentQueryParams(UnemploymentQueryParams): age: Literal[AgesLiteral] = Field( description="Age group to get unemployment for. Total indicates 15 years or over", default="total", - json_schema_extra={"choices": AGES}, + json_schema_extra={"choices": AGES}, # type: ignore ) seasonal_adjustment: bool = Field( description="Whether to get seasonally adjusted unemployment. Defaults to False.", @@ -131,10 +125,7 @@ class OECDUnemploymentFetcher( age = { "total": "Y_GE15", "15-24": "Y15T24", - "15-64": "Y15T64", - "15-74": "Y15T74", - "25-54": "Y25T54", - "55-64": "Y55T64", + "25+": "Y_GE25", }[query.age] seasonal_adjustment = "Y" if query.seasonal_adjustment else "N" -- cgit v1.2.3 From 5ba54725536a3eb8121f2ed7ea47076789abecea Mon Sep 17 00:00:00 2001 From: Danglewood <85772166+deeleeramone@users.noreply.github.com> Date: Thu, 4 Jul 2024 03:00:08 -0700 Subject: [BugFix] Fix Provider Interface Body Assignment Of Dict-Like Parameters (#6561) * fix provider interface body assignment for Dict-like parameters. * 3.9 safe --------- Co-authored-by: Igor Radovanovic <74266147+IgorWounds@users.noreply.github.com> --- .../core/openbb_core/app/provider_interface.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/openbb_platform/core/openbb_core/app/provider_interface.py b/openbb_platform/core/openbb_core/app/provider_interface.py index 6c9a558161a..8eb2f5371b6 100644 --- a/openbb_platform/core/openbb_core/app/provider_interface.py +++ b/openbb_platform/core/openbb_core/app/provider_interface.py @@ -15,7 +15,7 @@ from typing import ( Union, ) -from fastapi import Query +from fastapi import Body, Query from pydantic import ( BaseModel, ConfigDict, @@ -290,6 +290,23 @@ class ProviderInterface(metaclass=SingletonMeta): else: default = field.default + if ( + hasattr(annotation, "__name__") + and annotation.__name__ in ["Dict", "dict", "Data"] # type: ignore + or field.kw_only is True + ): + return DataclassField( + new_name, + annotation, + Body( + default=default, + title=provider_name, + description=description, + alias=field.alias or None, + json_schema_extra=getattr(field, "json_schema_extra", None), + ), + ) + if query: # We need to use query if we want the field description to show # up in the swagger, it's a fastapi limitation -- cgit v1.2.3