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

[Feature] Update chart creation so it doesn't break the command execution #6382

Merged
merged 3 commits into from
May 9, 2024
Merged
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
58 changes: 33 additions & 25 deletions openbb_platform/core/openbb_core/app/command_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,31 +304,38 @@ def _chart(
**kwargs,
) -> None:
"""Create a chart from the command output."""
if "charting" not in obbject.accessors:
raise OpenBBError(
"Charting is not installed. Please install `openbb-charting`."
)
chart_params = {}
extra_params = kwargs.get("extra_params", {})

if hasattr(extra_params, "__dict__") and hasattr(extra_params, "chart_params"):
chart_params = kwargs["extra_params"].__dict__.get("chart_params", {})
elif isinstance(extra_params, dict) and "chart_params" in extra_params:
chart_params = kwargs["extra_params"].get("chart_params", {})

if "chart_params" in kwargs and kwargs["chart_params"] is not None:
chart_params.update(kwargs.pop("chart_params", {}))

if (
"kwargs" in kwargs
and "chart_params" in kwargs["kwargs"]
and kwargs["kwargs"].get("chart_params") is not None
):
chart_params.update(kwargs.pop("kwargs", {}).get("chart_params", {}))

if chart_params:
kwargs.update(chart_params)
obbject.charting.show(render=False, **kwargs)
try:
if "charting" not in obbject.accessors:
raise OpenBBError(
"Charting is not installed. Please install `openbb-charting`."
)
chart_params = {}
extra_params = kwargs.get("extra_params", {})

if hasattr(extra_params, "__dict__") and hasattr(
extra_params, "chart_params"
):
chart_params = kwargs["extra_params"].__dict__.get("chart_params", {})
elif isinstance(extra_params, dict) and "chart_params" in extra_params:
chart_params = kwargs["extra_params"].get("chart_params", {})

if "chart_params" in kwargs and kwargs["chart_params"] is not None:
chart_params.update(kwargs.pop("chart_params", {}))

if (
"kwargs" in kwargs
and "chart_params" in kwargs["kwargs"]
and kwargs["kwargs"].get("chart_params") is not None
):
chart_params.update(kwargs.pop("kwargs", {}).get("chart_params", {}))

if chart_params:
kwargs.update(chart_params)
obbject.charting.show(render=False, **kwargs)
except Exception as e: # pylint: disable=broad-exception-caught
if Env().DEBUG_MODE:
raise OpenBBError(e) from e
warn(str(e), OpenBBWarning)

# pylint: disable=R0913, R0914
@classmethod
Expand Down Expand Up @@ -449,6 +456,7 @@ async def run(
except Exception as e:
if Env().DEBUG_MODE:
raise OpenBBError(e) from e
warn(str(e), OpenBBWarning)

return obbject

Expand Down
Loading