From 318b167223a94fe45cb33ae193d969a99f131751 Mon Sep 17 00:00:00 2001 From: Diogo Sousa Date: Thu, 28 Mar 2024 11:04:32 +0000 Subject: [PATCH 01/23] don't skipt charting tests --- openbb_platform/extensions/tests/conftest.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/openbb_platform/extensions/tests/conftest.py b/openbb_platform/extensions/tests/conftest.py index 7e3fbce9dc23..b8849169816a 100644 --- a/openbb_platform/extensions/tests/conftest.py +++ b/openbb_platform/extensions/tests/conftest.py @@ -1,6 +1,6 @@ """Custom pytest configuration for the extensions.""" -from typing import Any, Dict, List +from typing import Dict, List import pytest from openbb_core.app.router import CommandMap @@ -13,7 +13,7 @@ # ruff: noqa: SIM114 -def parametrize(argnames: str, argvalues: List[Dict[str, Any]], **kwargs): +def parametrize(argnames: str, argvalues: List, **kwargs): """Custom parametrize decorator that filters test cases based on the environment.""" routers, providers, obbject_ext = list_openbb_extensions() @@ -49,6 +49,10 @@ def decorator(function): elif "provider" not in args and function_name_v3 in commands: # Handle edge case filtered_argvalues.append(args) + elif extension_name in obbject_ext: + filtered_argvalues.append(args) + + # If filtered_argvalues is empty, pytest will skip the test! return pytest.mark.parametrize(argnames, filtered_argvalues, **kwargs)( function ) From f987524ff81b7718d888a4670b2419893ef4d81c Mon Sep 17 00:00:00 2001 From: hjoaquim Date: Thu, 28 Mar 2024 11:11:57 +0000 Subject: [PATCH 02/23] multiples does not have a charting implementation --- .../charting/integration/test_charting_api.py | 23 ------------------- 1 file changed, 23 deletions(-) diff --git a/openbb_platform/obbject_extensions/charting/integration/test_charting_api.py b/openbb_platform/obbject_extensions/charting/integration/test_charting_api.py index cacfac05daa4..f89c1b318bf5 100644 --- a/openbb_platform/obbject_extensions/charting/integration/test_charting_api.py +++ b/openbb_platform/obbject_extensions/charting/integration/test_charting_api.py @@ -75,29 +75,6 @@ def test_charting_equity_price_historical(params, headers): assert list(chart.keys()) == ["content", "format"] -@parametrize( - "params", - [({"symbol": "AAPL", "limit": 100, "chart": True})], -) -@pytest.mark.integration -def test_charting_equity_fundamental_multiples(params, headers): - """Test chart equity multiples.""" - params = {p: v for p, v in params.items() if v} - - query_str = get_querystring(params, []) - url = f"http://0.0.0.0:8000/api/v1/equity/fundamental/multiples?{query_str}" - result = requests.get(url, headers=headers, timeout=10) - assert isinstance(result, requests.Response) - assert result.status_code == 200 - - chart = result.json()["chart"] - fig = chart.pop("fig", {}) - - assert chart - assert not fig - assert list(chart.keys()) == ["content", "format"] - - @parametrize( "params", [ From 1ab8f9541b6f69b3afc4a175c46e3a921c50c59c Mon Sep 17 00:00:00 2001 From: hjoaquim Date: Thu, 28 Mar 2024 11:35:28 +0000 Subject: [PATCH 03/23] fix list index out of range --- .../charting/openbb_charting/charting_router.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/openbb_platform/obbject_extensions/charting/openbb_charting/charting_router.py b/openbb_platform/obbject_extensions/charting/openbb_charting/charting_router.py index 44b92a2c6c53..eb55ceeb5440 100644 --- a/openbb_platform/obbject_extensions/charting/openbb_charting/charting_router.py +++ b/openbb_platform/obbject_extensions/charting/openbb_charting/charting_router.py @@ -385,12 +385,9 @@ def z_score_standardization(data: pd.Series) -> pd.Series: + " Override this error by setting `allow_unsafe = True`." ) - y1_units = y_units[0] - + y1_units = y_units[0] if y_units else None y1title = y1_units - y2title = y_units[1] if len(y_units) > 1 else None - xtitle = "" # If the request was transformed, the y-axis will be shared under these conditions. From 7eb8c90fb522b7086959c9859ed72f6f35ca9c6e Mon Sep 17 00:00:00 2001 From: hjoaquim Date: Thu, 28 Mar 2024 12:07:22 +0000 Subject: [PATCH 04/23] mypy --- .../openbb_charting/charting_router.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/openbb_platform/obbject_extensions/charting/openbb_charting/charting_router.py b/openbb_platform/obbject_extensions/charting/openbb_charting/charting_router.py index eb55ceeb5440..08c27d8c12c2 100644 --- a/openbb_platform/obbject_extensions/charting/openbb_charting/charting_router.py +++ b/openbb_platform/obbject_extensions/charting/openbb_charting/charting_router.py @@ -1,7 +1,7 @@ """Charting router.""" import json -from typing import Any, Dict, Tuple +from typing import Any, Dict, Optional, Tuple, Union import pandas as pd from openbb_core.app.model.charts.chart import ChartFormat @@ -188,7 +188,6 @@ def technical_cones( **kwargs: TechnicalConesChartQueryParams, ) -> Tuple["OpenBBFigure", Dict[str, Any]]: """Volatility Cones Chart.""" - data = kwargs.get("data") if isinstance(data, pd.DataFrame) and not data.empty and "window" in data.columns: @@ -286,10 +285,9 @@ def technical_cones( def economy_fred_series( - **kwargs: FredSeriesChartQueryParams, + **kwargs: Union[Any, FredSeriesChartQueryParams], ) -> Tuple["OpenBBFigure", Dict[str, Any]]: """FRED Series Chart.""" - ytitle_dict = { "chg": "Change", "ch1": "Change From Year Ago", @@ -398,8 +396,9 @@ def z_score_standardization(data: pd.Series) -> pd.Series: y2title = None # Set the title for the chart. - if kwargs.get("title"): - title = kwargs.get("title") + title: str = "" + if isinstance(kwargs, dict) and title in kwargs: + title = kwargs["title"] else: if metadata.get(columns[0]): title = metadata.get(columns[0]).get("title") if len(columns) == 1 else "FRED Series" # type: ignore @@ -409,7 +408,7 @@ def z_score_standardization(data: pd.Series) -> pd.Series: title = f"{title} - {transform_title}" if transform_title else title # Define this to use as a check. - y3title = "" + y3title: Optional[str] = "" # Create the figure object with subplots. fig = OpenBBFigure().create_subplots( @@ -453,14 +452,14 @@ def z_score_standardization(data: pd.Series) -> pd.Series: if kwargs.get("y2title") and y2title is not None: y2title = kwargs.get("y2title") # Set the x-axis title, if suppiled. - if kwargs.get("xtitle"): - xtitle = kwargs.get("xtitle") + if isinstance(kwargs, dict) and "xtitle" in kwargs: + xtitle = kwargs["xtitle"] # If the data was normalized, set the title to reflect this. if normalize: y1title = None y2title = None y3title = None - title = f"{title} - Normalized" + title = f"{title} - Normalized" if title else "Normalized" # Now update the layout of the complete figure. fig.update_layout( From d12b1eb881692dccb031acae987b27305ce2f8f1 Mon Sep 17 00:00:00 2001 From: Diogo Sousa Date: Thu, 28 Mar 2024 12:13:54 +0000 Subject: [PATCH 05/23] mypy --- .../charting/openbb_charting/core/plotly_ta/data_classes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openbb_platform/obbject_extensions/charting/openbb_charting/core/plotly_ta/data_classes.py b/openbb_platform/obbject_extensions/charting/openbb_charting/core/plotly_ta/data_classes.py index aa0223bfdc95..f9c500ec6f1c 100644 --- a/openbb_platform/obbject_extensions/charting/openbb_charting/core/plotly_ta/data_classes.py +++ b/openbb_platform/obbject_extensions/charting/openbb_charting/core/plotly_ta/data_classes.py @@ -165,7 +165,7 @@ def get_options_dict(self, name: str) -> Dict[str, Optional[Arguments]]: @staticmethod def get_available_indicators() -> Tuple[str, ...]: """Return tuple of available indicators.""" - return list( + return tuple( TAIndicator.__annotations__["name"].__args__ # pylint: disable=E1101 ) From 18a8e6281f99cd92f022135503e37c84467140f9 Mon Sep 17 00:00:00 2001 From: Diogo Sousa Date: Thu, 28 Mar 2024 12:50:11 +0000 Subject: [PATCH 06/23] mypy ta class + base --- .../openbb_charting/core/plotly_ta/base.py | 24 ++++++++++++------- .../core/plotly_ta/ta_class.py | 2 +- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/openbb_platform/obbject_extensions/charting/openbb_charting/core/plotly_ta/base.py b/openbb_platform/obbject_extensions/charting/openbb_charting/core/plotly_ta/base.py index 126f3b195fc0..1d0ec43eb51b 100644 --- a/openbb_platform/obbject_extensions/charting/openbb_charting/core/plotly_ta/base.py +++ b/openbb_platform/obbject_extensions/charting/openbb_charting/core/plotly_ta/base.py @@ -1,4 +1,6 @@ -from typing import Any, Callable, Dict, Iterator, List, Optional, Type +"""Base class for charting plugins.""" + +from typing import Any, Callable, Dict, Iterator, List, Optional, Type, Union import pandas as pd @@ -6,7 +8,7 @@ def columns_regex(df_ta: pd.DataFrame, name: str) -> List[str]: - """Return columns that match regex name""" + """Return columns that match regex name.""" column_name = df_ta.filter(regex=rf"{name}(?=[^\d]|$)").columns.tolist() return column_name @@ -26,6 +28,7 @@ def __init__( self.attrs = attrs def __call__(self, *args: Any, **kwargs: Any) -> Any: + """Call the indicator function.""" return self.func(*args, **kwargs) @@ -39,6 +42,7 @@ class PluginMeta(type): __subplots__: List[str] = [] def __new__(mcs: Type["PluginMeta"], *args: Any, **kwargs: Any) -> "PluginMeta": + """Create a new instance of the class.""" name, bases, attrs = args indicators: Dict[str, Indicator] = {} cls_attrs: Dict[str, list] = { @@ -76,6 +80,7 @@ def __new__(mcs: Type["PluginMeta"], *args: Any, **kwargs: Any) -> "PluginMeta": return new_cls def __iter__(cls: Type["PluginMeta"]) -> Iterator[Indicator]: # type: ignore + """Iterate over the indicators.""" return iter(cls.__indicators__) # pylint: disable=unused-argument @@ -88,11 +93,11 @@ class PltTA(metaclass=PluginMeta): indicators: ChartIndicators intraday: bool = False - df_stock: pd.DataFrame - df_ta: pd.DataFrame + df_stock: Union[pd.DataFrame, pd.Series] + df_ta: Optional[pd.DataFrame] = None df_fib: pd.DataFrame close_column: Optional[str] = "close" - params: Dict[str, TAIndicator] = {} + params: Optional[Dict[str, TAIndicator]] = {} inchart_colors: List[str] = [] show_volume: bool = True @@ -104,6 +109,7 @@ class PltTA(metaclass=PluginMeta): # pylint: disable=unused-argument def __new__(cls, *args: Any, **kwargs: Any) -> "PltTA": + """Create a new instance of the class.""" if cls is PltTA: raise TypeError("Can't instantiate abstract class Plugin directly") self = super().__new__(cls) @@ -132,6 +138,7 @@ def __new__(cls, *args: Any, **kwargs: Any) -> "PltTA": @property def ma_mode(self) -> List[str]: + """Moving average mode.""" return list(set(self.__ma_mode__)) @ma_mode.setter @@ -139,7 +146,7 @@ def ma_mode(self, value: List[str]): self.__ma_mode__ = value def add_plugins(self, plugins: List["PltTA"]) -> None: - """Add plugins to current instance""" + """Add plugins to current instance.""" for plugin in plugins: for item in plugin.__indicators__: # pylint: disable=unnecessary-dunder-call @@ -161,7 +168,7 @@ def add_plugins(self, plugins: List["PltTA"]) -> None: getattr(self, attr).extend(value) def remove_plugins(self, plugins: List["PltTA"]) -> None: - """Remove plugins from current instance""" + """Remove plugins from current instance.""" for plugin in plugins: for item in plugin.__indicators__: delattr(self, item.name) @@ -171,10 +178,11 @@ def remove_plugins(self, plugins: List["PltTA"]) -> None: delattr(self, static_method) def __iter__(self) -> Iterator[Indicator]: + """Iterate over the indicators.""" return iter(self.__indicators__) def get_float_precision(self) -> str: - """Returns f-string precision format""" + """Returns f-string precision format.""" price = self.df_stock[self.close_column].tail(1).values[0] float_precision = ( ",.2f" if price > 1.10 else "" if len(str(price)) < 8 else ".6f" diff --git a/openbb_platform/obbject_extensions/charting/openbb_charting/core/plotly_ta/ta_class.py b/openbb_platform/obbject_extensions/charting/openbb_charting/core/plotly_ta/ta_class.py index ebe12307ed33..e8b0fc136992 100644 --- a/openbb_platform/obbject_extensions/charting/openbb_charting/core/plotly_ta/ta_class.py +++ b/openbb_platform/obbject_extensions/charting/openbb_charting/core/plotly_ta/ta_class.py @@ -88,7 +88,7 @@ class PlotlyTA(PltTA): inchart_colors: List[str] = [] plugins: List[Type[PltTA]] = [] - df_ta: pd.DataFrame = None + df_ta: Optional[pd.DataFrame] = None close_column: Optional[str] = "close" has_volume: bool = True show_volume: bool = True From 6d5cd69d54df8eb58e75761a7a20ce83f013999e Mon Sep 17 00:00:00 2001 From: Diogo Sousa Date: Thu, 28 Mar 2024 12:57:55 +0000 Subject: [PATCH 07/23] indicators mypy --- .../charting/openbb_charting/core/plotly_ta/base.py | 2 +- .../charting/openbb_charting/core/plotly_ta/ta_class.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/openbb_platform/obbject_extensions/charting/openbb_charting/core/plotly_ta/base.py b/openbb_platform/obbject_extensions/charting/openbb_charting/core/plotly_ta/base.py index 1d0ec43eb51b..d62d7d9731cb 100644 --- a/openbb_platform/obbject_extensions/charting/openbb_charting/core/plotly_ta/base.py +++ b/openbb_platform/obbject_extensions/charting/openbb_charting/core/plotly_ta/base.py @@ -91,7 +91,7 @@ def __init__(cls, *args: Any, **kwargs: Any) -> None: class PltTA(metaclass=PluginMeta): """The base class that all Plotly plugins must inherit from.""" - indicators: ChartIndicators + indicators: Optional[ChartIndicators] = None intraday: bool = False df_stock: Union[pd.DataFrame, pd.Series] df_ta: Optional[pd.DataFrame] = None diff --git a/openbb_platform/obbject_extensions/charting/openbb_charting/core/plotly_ta/ta_class.py b/openbb_platform/obbject_extensions/charting/openbb_charting/core/plotly_ta/ta_class.py index e8b0fc136992..9e8905e76908 100644 --- a/openbb_platform/obbject_extensions/charting/openbb_charting/core/plotly_ta/ta_class.py +++ b/openbb_platform/obbject_extensions/charting/openbb_charting/core/plotly_ta/ta_class.py @@ -113,10 +113,10 @@ def __new__(cls, *args, **kwargs): # We set the global variable to the instance of the class so that # the plugins are only loaded once PLOTLY_TA = super().__new__(cls) - PLOTLY_TA._locate_plugins( + PLOTLY_TA._locate_plugins( # type: ignore[attr-defined] getattr(cls.charting_settings, "debug_mode", False) ) - PLOTLY_TA.add_plugins(PLOTLY_TA.plugins) + PLOTLY_TA.add_plugins(PLOTLY_TA.plugins) # type: ignore[attr-defined] return PLOTLY_TA @@ -289,7 +289,7 @@ def _locate_plugins(debug: Optional[bool] = False) -> None: def _clear_data(self): """Clear and reset all data to default values.""" self.df_stock = None - self.indicators = {} + self.indicators = None self.params = None self.intraday = False self.show_volume = True From 55ea434777333edd0c7cd390419d4747d7717af1 Mon Sep 17 00:00:00 2001 From: Diogo Sousa Date: Thu, 28 Mar 2024 13:01:00 +0000 Subject: [PATCH 08/23] sync precommit with ci --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 60e62785b571..da3cfd4d3e99 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -50,7 +50,7 @@ repos: entry: mypy language: python "types_or": [python, pyi] - args: ["--ignore-missing-imports", "--scripts-are-modules"] + args: ["--ignore-missing-imports", "--scripts-are-modules", "--check-untyped-defs"] require_serial: true - repo: https://github.com/kynan/nbstripout rev: 0.6.1 From bdd487c9023954915781a9a5868fb53773afe889 Mon Sep 17 00:00:00 2001 From: Diogo Sousa Date: Thu, 28 Mar 2024 13:07:37 +0000 Subject: [PATCH 09/23] sync ci with precommit --- .github/workflows/linting.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/linting.yml b/.github/workflows/linting.yml index ccabe3a349d8..ff98d8e8f6e4 100644 --- a/.github/workflows/linting.yml +++ b/.github/workflows/linting.yml @@ -69,7 +69,7 @@ jobs: # Run linters for openbb_platform if [ -n "${{ env.platform_files }}" ]; then pylint ${{ env.platform_files }} - mypy ${{ env.platform_files }} --ignore-missing-imports --check-untyped-defs + mypy ${{ env.platform_files }} --ignore-missing-imports --scripts-are-modules --check-untyped-defs else echo "No Python files changed in openbb_platform" fi From be0940b50d856c4fa3cc378da745fdacd740f8fe Mon Sep 17 00:00:00 2001 From: Diogo Sousa Date: Thu, 28 Mar 2024 13:14:26 +0000 Subject: [PATCH 10/23] revert --- .../charting/openbb_charting/core/plotly_ta/ta_class.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openbb_platform/obbject_extensions/charting/openbb_charting/core/plotly_ta/ta_class.py b/openbb_platform/obbject_extensions/charting/openbb_charting/core/plotly_ta/ta_class.py index 9e8905e76908..cb8020a2eb4b 100644 --- a/openbb_platform/obbject_extensions/charting/openbb_charting/core/plotly_ta/ta_class.py +++ b/openbb_platform/obbject_extensions/charting/openbb_charting/core/plotly_ta/ta_class.py @@ -289,7 +289,7 @@ def _locate_plugins(debug: Optional[bool] = False) -> None: def _clear_data(self): """Clear and reset all data to default values.""" self.df_stock = None - self.indicators = None + self.indicators = {} self.params = None self.intraday = False self.show_volume = True From 22b3ff727ce65c71182a8d8bf023743814750cf6 Mon Sep 17 00:00:00 2001 From: Diogo Sousa Date: Thu, 28 Mar 2024 13:17:06 +0000 Subject: [PATCH 11/23] revert --- .../charting/openbb_charting/core/plotly_ta/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openbb_platform/obbject_extensions/charting/openbb_charting/core/plotly_ta/base.py b/openbb_platform/obbject_extensions/charting/openbb_charting/core/plotly_ta/base.py index d62d7d9731cb..1d0ec43eb51b 100644 --- a/openbb_platform/obbject_extensions/charting/openbb_charting/core/plotly_ta/base.py +++ b/openbb_platform/obbject_extensions/charting/openbb_charting/core/plotly_ta/base.py @@ -91,7 +91,7 @@ def __init__(cls, *args: Any, **kwargs: Any) -> None: class PltTA(metaclass=PluginMeta): """The base class that all Plotly plugins must inherit from.""" - indicators: Optional[ChartIndicators] = None + indicators: ChartIndicators intraday: bool = False df_stock: Union[pd.DataFrame, pd.Series] df_ta: Optional[pd.DataFrame] = None From a8f3d1d10be03ee133a308a5289e0b2d5043f329 Mon Sep 17 00:00:00 2001 From: Diogo Sousa Date: Thu, 28 Mar 2024 13:59:20 +0000 Subject: [PATCH 12/23] mypy indicators --- .../charting/openbb_charting/core/plotly_ta/ta_class.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openbb_platform/obbject_extensions/charting/openbb_charting/core/plotly_ta/ta_class.py b/openbb_platform/obbject_extensions/charting/openbb_charting/core/plotly_ta/ta_class.py index cb8020a2eb4b..fb6da83fc4fe 100644 --- a/openbb_platform/obbject_extensions/charting/openbb_charting/core/plotly_ta/ta_class.py +++ b/openbb_platform/obbject_extensions/charting/openbb_charting/core/plotly_ta/ta_class.py @@ -289,7 +289,7 @@ def _locate_plugins(debug: Optional[bool] = False) -> None: def _clear_data(self): """Clear and reset all data to default values.""" self.df_stock = None - self.indicators = {} + self.indicators = ChartIndicators.from_dict(dict(dict())) self.params = None self.intraday = False self.show_volume = True From 63c0dffcbd4b46e4a7f5258caba531c99a5c1531 Mon Sep 17 00:00:00 2001 From: Diogo Sousa Date: Thu, 28 Mar 2024 14:05:01 +0000 Subject: [PATCH 13/23] fix mypy --- .../charting/openbb_charting/core/plotly_ta/ta_class.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/openbb_platform/obbject_extensions/charting/openbb_charting/core/plotly_ta/ta_class.py b/openbb_platform/obbject_extensions/charting/openbb_charting/core/plotly_ta/ta_class.py index fb6da83fc4fe..f16557c1ac85 100644 --- a/openbb_platform/obbject_extensions/charting/openbb_charting/core/plotly_ta/ta_class.py +++ b/openbb_platform/obbject_extensions/charting/openbb_charting/core/plotly_ta/ta_class.py @@ -112,11 +112,11 @@ def __new__(cls, *args, **kwargs): # Creates the instance of the class and loads the plugins # We set the global variable to the instance of the class so that # the plugins are only loaded once - PLOTLY_TA = super().__new__(cls) + PLOTLY_TA = super().__new__(cls) # type: ignore[attr-defined] PLOTLY_TA._locate_plugins( # type: ignore[attr-defined] getattr(cls.charting_settings, "debug_mode", False) ) - PLOTLY_TA.add_plugins(PLOTLY_TA.plugins) # type: ignore[attr-defined] + PLOTLY_TA.add_plugins(PLOTLY_TA.plugins) # type: ignore[assignment] return PLOTLY_TA From bbae837a17f744fa0e8d03aa4e47bc2fde019a65 Mon Sep 17 00:00:00 2001 From: Diogo Sousa Date: Thu, 28 Mar 2024 14:10:29 +0000 Subject: [PATCH 14/23] fix hastype --- .../obbject_extensions/charting/openbb_charting/core/backend.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openbb_platform/obbject_extensions/charting/openbb_charting/core/backend.py b/openbb_platform/obbject_extensions/charting/openbb_charting/core/backend.py index 457df7d5981d..2307f3993fcb 100644 --- a/openbb_platform/obbject_extensions/charting/openbb_charting/core/backend.py +++ b/openbb_platform/obbject_extensions/charting/openbb_charting/core/backend.py @@ -221,7 +221,7 @@ def send_figure( self.send_outgoing(outgoing) if export_image and isinstance(export_image, Path): - if self.loop.is_closed(): + if self.loop.is_closed(): # type: ignore[has-type] # Create a new event loop self.loop = asyncio.new_event_loop() asyncio.set_event_loop(self.loop) From 35fd4633d5879d99ac14b4c07b9d61aea9b6d7af Mon Sep 17 00:00:00 2001 From: Diogo Sousa Date: Thu, 28 Mar 2024 14:22:54 +0000 Subject: [PATCH 15/23] type ignore --- .../charting/openbb_charting/core/plotly_ta/ta_class.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/openbb_platform/obbject_extensions/charting/openbb_charting/core/plotly_ta/ta_class.py b/openbb_platform/obbject_extensions/charting/openbb_charting/core/plotly_ta/ta_class.py index f16557c1ac85..8a5085534bcb 100644 --- a/openbb_platform/obbject_extensions/charting/openbb_charting/core/plotly_ta/ta_class.py +++ b/openbb_platform/obbject_extensions/charting/openbb_charting/core/plotly_ta/ta_class.py @@ -112,11 +112,11 @@ def __new__(cls, *args, **kwargs): # Creates the instance of the class and loads the plugins # We set the global variable to the instance of the class so that # the plugins are only loaded once - PLOTLY_TA = super().__new__(cls) # type: ignore[attr-defined] + PLOTLY_TA = super().__new__(cls) # type: ignore[attr-defined, assignment] PLOTLY_TA._locate_plugins( # type: ignore[attr-defined] getattr(cls.charting_settings, "debug_mode", False) ) - PLOTLY_TA.add_plugins(PLOTLY_TA.plugins) # type: ignore[assignment] + PLOTLY_TA.add_plugins(PLOTLY_TA.plugins) # type: ignore[attr-defined, assignment] return PLOTLY_TA From 42782a18920863c84702477090fcf1899323de84 Mon Sep 17 00:00:00 2001 From: hjoaquim Date: Thu, 28 Mar 2024 14:32:39 +0000 Subject: [PATCH 16/23] mypy --- .../core/plotly_ta/data_classes.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/openbb_platform/obbject_extensions/charting/openbb_charting/core/plotly_ta/data_classes.py b/openbb_platform/obbject_extensions/charting/openbb_charting/core/plotly_ta/data_classes.py index f9c500ec6f1c..d06a2c6f42cf 100644 --- a/openbb_platform/obbject_extensions/charting/openbb_charting/core/plotly_ta/data_classes.py +++ b/openbb_platform/obbject_extensions/charting/openbb_charting/core/plotly_ta/data_classes.py @@ -69,7 +69,9 @@ class TAIndicator: def __post_init__(self): """Post init.""" - self.args = [Arguments(**arg) for arg in self.args] + self.args = [ + arg if isinstance(arg, Arguments) else Arguments(**arg) for arg in self.args + ] def __iter__(self): """Return iterator.""" @@ -100,11 +102,13 @@ class ChartIndicators: def __post_init__(self): """Post init.""" - self.indicators = ( - [TAIndicator(**indicator) for indicator in self.indicators] - if self.indicators - else [] - ) + if self.indicators: + self.indicators = [ + TAIndicator(**indicator) if isinstance(indicator, dict) else indicator + for indicator in self.indicators + ] + else: + self.indicators = [] def get_indicator(self, name: str) -> Union[TAIndicator, None]: """Return indicator with given name.""" From 889b51a143e43b82844a6d1766ee810112236530 Mon Sep 17 00:00:00 2001 From: hjoaquim Date: Thu, 28 Mar 2024 14:38:19 +0000 Subject: [PATCH 17/23] mypy --- .../openbb_charting/core/plotly_ta/data_classes.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/openbb_platform/obbject_extensions/charting/openbb_charting/core/plotly_ta/data_classes.py b/openbb_platform/obbject_extensions/charting/openbb_charting/core/plotly_ta/data_classes.py index d06a2c6f42cf..5d2262369a9e 100644 --- a/openbb_platform/obbject_extensions/charting/openbb_charting/core/plotly_ta/data_classes.py +++ b/openbb_platform/obbject_extensions/charting/openbb_charting/core/plotly_ta/data_classes.py @@ -70,7 +70,12 @@ class TAIndicator: def __post_init__(self): """Post init.""" self.args = [ - arg if isinstance(arg, Arguments) else Arguments(**arg) for arg in self.args + ( + arg + if isinstance(arg, Arguments) + else Arguments(label=arg["label"], values=arg["values"]) + ) + for arg in self.args ] def __iter__(self): From 7976c07b3674d8f95eb7747ef0fe113c99b4ff76 Mon Sep 17 00:00:00 2001 From: hjoaquim Date: Thu, 28 Mar 2024 14:42:21 +0000 Subject: [PATCH 18/23] mypy --- .../openbb_charting/core/plotly_ta/data_classes.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/openbb_platform/obbject_extensions/charting/openbb_charting/core/plotly_ta/data_classes.py b/openbb_platform/obbject_extensions/charting/openbb_charting/core/plotly_ta/data_classes.py index 5d2262369a9e..d06a2c6f42cf 100644 --- a/openbb_platform/obbject_extensions/charting/openbb_charting/core/plotly_ta/data_classes.py +++ b/openbb_platform/obbject_extensions/charting/openbb_charting/core/plotly_ta/data_classes.py @@ -70,12 +70,7 @@ class TAIndicator: def __post_init__(self): """Post init.""" self.args = [ - ( - arg - if isinstance(arg, Arguments) - else Arguments(label=arg["label"], values=arg["values"]) - ) - for arg in self.args + arg if isinstance(arg, Arguments) else Arguments(**arg) for arg in self.args ] def __iter__(self): From 1dc0215e8d97a543c2069056f51a1bc70e6c3409 Mon Sep 17 00:00:00 2001 From: Diogo Sousa Date: Thu, 28 Mar 2024 15:02:39 +0000 Subject: [PATCH 19/23] does this work? --- .../core/plotly_ta/data_classes.py | 42 ++++++++++++++----- 1 file changed, 32 insertions(+), 10 deletions(-) diff --git a/openbb_platform/obbject_extensions/charting/openbb_charting/core/plotly_ta/data_classes.py b/openbb_platform/obbject_extensions/charting/openbb_charting/core/plotly_ta/data_classes.py index d06a2c6f42cf..348653ad4413 100644 --- a/openbb_platform/obbject_extensions/charting/openbb_charting/core/plotly_ta/data_classes.py +++ b/openbb_platform/obbject_extensions/charting/openbb_charting/core/plotly_ta/data_classes.py @@ -174,16 +174,38 @@ def get_available_indicators() -> Tuple[str, ...]: ) @classmethod - def from_dict(cls, indicators: Dict[str, Dict[str, Any]]) -> "ChartIndicators": - """Return ChartIndicators from dictionary.""" - data = [] - for indicator in indicators: - args = [] - for arg in indicators[indicator]: - args.append({"label": arg, "values": indicators[indicator][arg]}) - data.append({"name": indicator, "args": args}) - - return cls(indicators=data) # type: ignore + def from_dict( + cls, indicators: Dict[str, Dict[str, List[Dict[str, Any]]]] + ) -> "ChartIndicators": + """Return ChartIndicators from dictionary. + + Example + ------- + ChartIndicators.from_dict( + { + "ad": { + "args": [ + { + "label": "AD_LABEL", + "values": [1, 2, 3], + } + ] + } + } + ) + """ + return cls( + indicators=[ + TAIndicator( + name=name, # type: ignore[arg-type] + args=[ + Arguments(label=label, values=values) + for label, values in args.items() + ], + ) + for name, args in indicators.items() + ] + ) def to_dataframe( self, df_ta: pd.DataFrame, ma_mode: Optional[List[str]] = None From c607d02b67a4c94bad797230ae30feb85b746d3a Mon Sep 17 00:00:00 2001 From: Diogo Sousa Date: Thu, 28 Mar 2024 15:07:21 +0000 Subject: [PATCH 20/23] remove post inits --- .../core/plotly_ta/data_classes.py | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/openbb_platform/obbject_extensions/charting/openbb_charting/core/plotly_ta/data_classes.py b/openbb_platform/obbject_extensions/charting/openbb_charting/core/plotly_ta/data_classes.py index 348653ad4413..43836fc6c465 100644 --- a/openbb_platform/obbject_extensions/charting/openbb_charting/core/plotly_ta/data_classes.py +++ b/openbb_platform/obbject_extensions/charting/openbb_charting/core/plotly_ta/data_classes.py @@ -67,12 +67,6 @@ class TAIndicator: ] args: List[Arguments] - def __post_init__(self): - """Post init.""" - self.args = [ - arg if isinstance(arg, Arguments) else Arguments(**arg) for arg in self.args - ] - def __iter__(self): """Return iterator.""" return iter(self.args) @@ -100,16 +94,6 @@ class ChartIndicators: indicators: Optional[List[TAIndicator]] = None - def __post_init__(self): - """Post init.""" - if self.indicators: - self.indicators = [ - TAIndicator(**indicator) if isinstance(indicator, dict) else indicator - for indicator in self.indicators - ] - else: - self.indicators = [] - def get_indicator(self, name: str) -> Union[TAIndicator, None]: """Return indicator with given name.""" output = None From b07620325266d8036c350c0ce1f595d0460524c8 Mon Sep 17 00:00:00 2001 From: Diogo Sousa Date: Thu, 28 Mar 2024 15:17:57 +0000 Subject: [PATCH 21/23] this --- openbb_terminal/core/plots/plotly_ta/ta_class.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openbb_terminal/core/plots/plotly_ta/ta_class.py b/openbb_terminal/core/plots/plotly_ta/ta_class.py index 98dba3a80467..0456cec5fa41 100644 --- a/openbb_terminal/core/plots/plotly_ta/ta_class.py +++ b/openbb_terminal/core/plots/plotly_ta/ta_class.py @@ -155,7 +155,7 @@ def __plot__( df_stock = df_stock.to_frame() if not isinstance(indicators, ChartIndicators): - indicators = ChartIndicators.from_dict(indicators or dict(dict())) + indicators = ChartIndicators.from_dict(indicators or {}) self.indicators = indicators self.intraday = df_stock.index[-2].time() != df_stock.index[-1].time() From 63b51408de1167739c1dc75ffb53c50332ce3f82 Mon Sep 17 00:00:00 2001 From: Diogo Sousa Date: Thu, 28 Mar 2024 15:18:51 +0000 Subject: [PATCH 22/23] this --- .../charting/openbb_charting/core/plotly_ta/ta_class.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openbb_platform/obbject_extensions/charting/openbb_charting/core/plotly_ta/ta_class.py b/openbb_platform/obbject_extensions/charting/openbb_charting/core/plotly_ta/ta_class.py index 8a5085534bcb..04bd73bf686e 100644 --- a/openbb_platform/obbject_extensions/charting/openbb_charting/core/plotly_ta/ta_class.py +++ b/openbb_platform/obbject_extensions/charting/openbb_charting/core/plotly_ta/ta_class.py @@ -180,7 +180,7 @@ def __plot__( df_stock = df_stock.to_frame() if not isinstance(indicators, ChartIndicators): - indicators = ChartIndicators.from_dict(indicators or dict(dict())) + indicators = ChartIndicators.from_dict(indicators or {}) # Apply to_datetime to the index in a way that handles daylight savings. df_stock.loc[:, "date"] = df_stock.index # type: ignore From 9473e00e4870dcc59affabf52eef55f1eb57aa66 Mon Sep 17 00:00:00 2001 From: Diogo Sousa Date: Thu, 28 Mar 2024 15:33:03 +0000 Subject: [PATCH 23/23] and this --- .../charting/openbb_charting/core/plotly_ta/ta_class.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openbb_platform/obbject_extensions/charting/openbb_charting/core/plotly_ta/ta_class.py b/openbb_platform/obbject_extensions/charting/openbb_charting/core/plotly_ta/ta_class.py index 04bd73bf686e..46b2af6cd6b5 100644 --- a/openbb_platform/obbject_extensions/charting/openbb_charting/core/plotly_ta/ta_class.py +++ b/openbb_platform/obbject_extensions/charting/openbb_charting/core/plotly_ta/ta_class.py @@ -289,7 +289,7 @@ def _locate_plugins(debug: Optional[bool] = False) -> None: def _clear_data(self): """Clear and reset all data to default values.""" self.df_stock = None - self.indicators = ChartIndicators.from_dict(dict(dict())) + self.indicators = ChartIndicators.from_dict({}) self.params = None self.intraday = False self.show_volume = True