Skip to content

Commit

Permalink
Merge branch 'develop' into feature/cli-unit-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
IgorWounds authored May 13, 2024
2 parents 8baa65c + f47e7ad commit c9d7fe4
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 201 deletions.
2 changes: 1 addition & 1 deletion assets/extensions/provider.json
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@
},
{
"packageName": "openbb-polygon",
"reprName": "Polygon",
"reprName": "Polygon.io",
"description": "The Polygon.io Stocks API provides REST endpoints that let you query\nthe latest market data from all US stock exchanges. You can also find data on\ncompany financials, stock market holidays, corporate actions, and more.",
"credentials": [
"polygon_api_key"
Expand Down
62 changes: 0 additions & 62 deletions cli/openbb_cli/config/setup.py
Original file line number Diff line number Diff line change
@@ -1,71 +1,9 @@
"""Configuration for the CLI."""

import copy
from pathlib import Path
from typing import TYPE_CHECKING, List, Optional, TypeVar

from openbb_cli.config.constants import ENV_FILE_SETTINGS, SETTINGS_DIRECTORY

if TYPE_CHECKING:
from openbb_charting.core.openbb_figure import OpenBBFigure

# ruff: noqa:PLW0603

OpenBBFigureT = TypeVar("OpenBBFigureT", bound="OpenBBFigure")
HOLD: bool = False
COMMAND_ON_CHART: bool = True
current_figure: Optional[OpenBBFigureT] = None # type: ignore
new_axis: bool = True
legends: List = []
last_legend = ""


# pylint: disable=global-statement
def set_last_legend(leg: str):
"""Set the last legend."""
global last_legend
last_legend = copy.deepcopy(leg)


def reset_legend() -> None:
"""Reset the legend."""
global legends
legends = []


def get_legends() -> list:
"""Get the legends."""
return legends


def set_same_axis() -> None:
"""Set the same axis."""
global new_axis
new_axis = False


def set_new_axis() -> None:
"""Set the new axis."""
global new_axis
new_axis = True


def make_new_axis() -> bool:
"""Make a new axis."""
return new_axis


def get_current_figure() -> Optional["OpenBBFigure"]:
"""Get the current figure."""
return current_figure


def set_current_figure(fig: Optional[OpenBBFigureT] = None):
"""Set the current figure."""
# pylint: disable=global-statement
global current_figure
current_figure = fig


def bootstrap():
"""Setup pre-launch configurations for the CLI."""
Expand Down
124 changes: 0 additions & 124 deletions cli/openbb_cli/controllers/base_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from typing import Any, Dict, List, Literal, Optional, Union

import pandas as pd
from openbb_cli.config import setup
from openbb_cli.config.completer import NestedCompleter
from openbb_cli.config.constants import SCRIPT_TAGS
from openbb_cli.controllers.choices import build_controller_choice_map
Expand Down Expand Up @@ -63,14 +62,12 @@ class BaseController(metaclass=ABCMeta):
"r",
"reset",
"stop",
"hold",
"whoami",
"results",
]

CHOICES_COMMANDS: List[str] = []
CHOICES_MENUS: List[str] = []
HOLD_CHOICES: dict = {}
NEWS_CHOICES: dict = {}
COMMAND_SEPARATOR = "/"
KEYS_MENU = "keys" + COMMAND_SEPARATOR
Expand Down Expand Up @@ -166,113 +163,6 @@ def load_class(self, class_ins, *args, **kwargs):
return old_class.menu()
return class_ins(*args, **kwargs).menu()

def call_hold(self, other_args: List[str]) -> None:
"""Process hold command."""
self.save_class()
parser = argparse.ArgumentParser(
add_help=False,
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
prog="hold",
description="Turn on figure holding. This will stop showing images until hold off is run.",
)
parser.add_argument(
"-o",
"--option",
choices=["on", "off"],
type=str,
default="off",
dest="option",
)
parser.add_argument(
"-s",
"--sameaxis",
action="store_true",
default=False,
help="Put plots on the same axis. Best when numbers are on similar scales",
dest="axes",
)
parser.add_argument(
"--title",
type=str,
default="",
dest="title",
nargs="+",
help="When using hold off, this sets the title for the figure.",
)
if other_args and "-" not in other_args[0][0]:
other_args.insert(0, "-o")

ns_parser = self.parse_known_args_and_warn(
parser,
other_args,
)
if ns_parser:
if ns_parser.option == "on":
setup.HOLD = True
setup.COMMAND_ON_CHART = False
if ns_parser.axes:
setup.set_same_axis()
else:
setup.set_new_axis()
if ns_parser.option == "off":
setup.HOLD = False
if setup.get_current_figure() is not None:
# create a subplot
fig = setup.get_current_figure()
if fig is None:
return
if not fig.has_subplots and not setup.make_new_axis():
fig.set_subplots(1, 1, specs=[[{"secondary_y": True}]])

if setup.make_new_axis():
for i, trace in enumerate(fig.select_traces()):
trace.yaxis = f"y{i+1}"

if i != 0:
fig.update_layout(
{
f"yaxis{i+1}": dict(
side="left",
overlaying="y",
showgrid=True,
showline=False,
zeroline=False,
automargin=True,
ticksuffix=(
" " * (i - 1) if i > 1 else ""
),
tickfont=dict(
size=18,
),
title=dict(
font=dict(
size=15,
),
standoff=0,
),
),
}
)
# pylint: disable=undefined-loop-variable
fig.update_layout(margin=dict(l=30 * i))

else:
fig.update_yaxes(title="")

if any(setup.get_legends()):
for trace, new_name in zip(
fig.select_traces(), setup.get_legends()
):
if new_name:
trace.name = new_name

fig.update_layout(title=" ".join(ns_parser.title))
fig.show()
setup.COMMAND_ON_CHART = True

setup.set_current_figure(None)
setup.reset_legend()

def save_class(self) -> None:
"""Save the current instance of the class to be loaded later."""
if session.settings.REMEMBER_CONTEXTS:
Expand Down Expand Up @@ -832,16 +722,6 @@ def parse_known_args_and_warn(
"-h", "--help", action="store_true", help="show this help message"
)

if setup.HOLD:
parser.add_argument(
"--legend",
type=str,
dest="hold_legend_str",
default="",
nargs="+",
help="Label for legend when hold is on.",
)

if export_allowed != "no_export":
choices_export = []
help_export = "Does not export!"
Expand Down Expand Up @@ -925,10 +805,6 @@ def parse_known_args_and_warn(

return None

# This protects against the hidden loads in stocks/fa
if parser.prog != "load" and setup.HOLD:
setup.set_last_legend(" ".join(ns_parser.hold_legend_str))

if l_unknown_args:
session.console.print(
f"The following args couldn't be interpreted: {l_unknown_args}"
Expand Down
6 changes: 1 addition & 5 deletions cli/openbb_cli/controllers/cli_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,6 @@ def update_runtime_choices(self):
if session.prompt_session and session.settings.USE_PROMPT_TOOLKIT:
# choices: dict = self.choices_default
choices: dict = {c: {} for c in self.controller_choices} # type: ignore
choices["hold"] = {c: None for c in ["on", "off", "-s", "--sameaxis"]}
choices["hold"]["off"] = {"--title": None}

self.ROUTINE_FILES = {
filepath.name: filepath # type: ignore
Expand Down Expand Up @@ -199,8 +197,6 @@ def update_runtime_choices(self):
"-d": "--description",
"--public": None,
"-p": "--public",
"--local": None,
"-l": "--local",
"--tag1": {c: None for c in constants.SCRIPT_TAGS},
"--tag2": {c: None for c in constants.SCRIPT_TAGS},
"--tag3": {c: None for c in constants.SCRIPT_TAGS},
Expand Down Expand Up @@ -481,7 +477,7 @@ def call_exe(self, other_args: List[str]):

except FileNotFoundError:
session.console.print(
f"[red]File '{routine_path}' doesn't exist.[/red]\n"
f"[red]File '{routine_path}' doesn't exist.[/red]"
)
return

Expand Down
4 changes: 2 additions & 2 deletions openbb_platform/core/openbb_core/app/model/credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def prepare(
formatted[c] = (
Optional[OBBSecretStr],
Field(
default=None, description=origin
default=None, description=origin, alias=c.upper()
), # register the credential origin (obbject, providers)
)

Expand Down Expand Up @@ -88,7 +88,7 @@ def load(self) -> BaseModel:
self.from_obbject()
return create_model( # type: ignore
"Credentials",
__config__=ConfigDict(validate_assignment=True),
__config__=ConfigDict(validate_assignment=True, populate_by_name=True),
**self.prepare(self.credentials),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ def platform2hub(self, credentials: Credentials) -> HubUserSettings:
settings = self._hub_user_settings or HubUserSettings()
for v4_k, v in sorted(credentials.items()):
v3_k = self.V4TOV3.get(v4_k, None)
# If v3 key was there, we keep it
# If v3 key was in the hub already, we keep it
k = v3_k if v3_k in settings.features_keys else v4_k
settings.features_keys[k] = v
return settings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"MarketIndices": PolygonIndexHistoricalFetcher,
"MarketSnapshots": PolygonMarketSnapshotsFetcher,
},
repr_name="Polygon",
repr_name="Polygon.io",
v3_credentials=["API_POLYGON_KEY"],
instructions='Go to: https://polygon.io\n\n![Polygon](https://user-images.githubusercontent.com/46355364/207825623-fcd7f0a3-131a-4294-808c-754c13e38e2a.png)\n\nClick on, "Get your Free API Key".\n\n![Polygon](https://user-images.githubusercontent.com/46355364/207825952-ca5540ec-6ed2-4cef-a0ed-bb50b813932c.png)\n\nAfter signing up, the API Key is found at the bottom of the account dashboard page.\n\n![Polygon](https://user-images.githubusercontent.com/46355364/207826258-b1f318fa-fd9c-41d9-bf5c-fe16722e6601.png)', # noqa: E501 pylint: disable=line-too-long
logo_url="https://polygon.io/_next/image?url=%2Flogo.svg&w=640&q=75",
Expand Down
10 changes: 5 additions & 5 deletions website/content/excel/data-slicer.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ To help you slice parts of data, we provide the [OBB.GET](https://docs.openbb.co

- Suppose you called an `OBB.` function and it returned the following data at cells A1:D3:

| period_ending | revenue | cost_of_revenue | gross_profit |
|---|---|---|---|---|
| 2023/09/30 | 383 285 000 000.00 | 214 137 000 000.00 | 169 148 000 000.00 |
| 2022/09/24 | 394 328 000 000.00 | 223 546 000 000.00 | 170 782 000 000.00 |
| 2021/09/25 | 365 817 000 000.00 | 212 981 000 000.00 | 152 836 000 000.00 |
| period_ending | revenue | cost_of_revenue | gross_profit |
|---------------|--------------------|--------------------|--------------------|
| 2023/09/30 | 383 285 000 000.00 | 214 137 000 000.00 | 169 148 000 000.00 |
| 2022/09/24 | 394 328 000 000.00 | 223 546 000 000.00 | 170 782 000 000.00 |
| 2021/09/25 | 365 817 000 000.00 | 212 981 000 000.00 | 152 836 000 000.00 |

- Slicing a single row:

Expand Down

0 comments on commit c9d7fe4

Please sign in to comment.