mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-11-01 23:12:21 +00:00
[BugFix] Fix broken --sheet-name argument (#6401)
* remove hold command and its references * remove --local flag as we don't use it anymore @IgorWounds * reset package folder * reset reference * unnecessary line break removed * better handling of obbjects before printing/table/chart also fixes the sheet_name issue when writing to excel * fix linting; also, dataframe creation in the right place * proper handling of sheet name * orient to columns instead --------- Co-authored-by: Danglewood <85772166+deeleeramone@users.noreply.github.com> Co-authored-by: Igor Radovanovic <74266147+IgorWounds@users.noreply.github.com>
This commit is contained in:
@@ -153,54 +153,65 @@ class PlatformController(BaseController):
|
||||
ns_parser = self._intersect_data_processing_commands(ns_parser)
|
||||
|
||||
obbject = translator.execute_func(parsed_args=ns_parser)
|
||||
df: pd.DataFrame = None
|
||||
df: pd.DataFrame = pd.DataFrame()
|
||||
fig: OpenBBFigure = None
|
||||
title = f"{self.PATH}{translator.func.__name__}"
|
||||
|
||||
if obbject:
|
||||
if session.max_obbjects_exceeded():
|
||||
session.obbject_registry.remove()
|
||||
|
||||
# use the obbject to store the command so we can display it later on results
|
||||
obbject.extra["command"] = f"{title} {' '.join(other_args)}"
|
||||
if isinstance(obbject, OBBject) and obbject.results:
|
||||
if session.max_obbjects_exceeded():
|
||||
session.obbject_registry.remove()
|
||||
session.console.print(
|
||||
"[yellow]Maximum number of OBBjects reached. The oldest entry was removed.[yellow]"
|
||||
)
|
||||
|
||||
session.obbject_registry.register(obbject)
|
||||
# we need to force to re-link so that the new obbject
|
||||
# is immediately available for data processing commands
|
||||
self._link_obbject_to_data_processing_commands()
|
||||
# also update the completer
|
||||
self.update_completer(self.choices_default)
|
||||
# use the obbject to store the command so we can display it later on results
|
||||
obbject.extra["command"] = f"{title} {' '.join(other_args)}"
|
||||
|
||||
if session.settings.SHOW_MSG_OBBJECT_REGISTRY and isinstance(
|
||||
obbject, OBBject
|
||||
):
|
||||
session.console.print("Added OBBject to registry.")
|
||||
register_result = session.obbject_registry.register(obbject)
|
||||
|
||||
if hasattr(ns_parser, "chart") and ns_parser.chart:
|
||||
obbject.show()
|
||||
fig = obbject.chart.fig
|
||||
if hasattr(obbject, "to_dataframe"):
|
||||
# we need to force to re-link so that the new obbject
|
||||
# is immediately available for data processing commands
|
||||
self._link_obbject_to_data_processing_commands()
|
||||
# also update the completer
|
||||
self.update_completer(self.choices_default)
|
||||
|
||||
if (
|
||||
session.settings.SHOW_MSG_OBBJECT_REGISTRY
|
||||
and register_result
|
||||
):
|
||||
session.console.print("Added OBBject to registry.")
|
||||
|
||||
# making the dataframe available
|
||||
# either for printing or exporting (or both)
|
||||
df = obbject.to_dataframe()
|
||||
|
||||
if hasattr(ns_parser, "chart") and ns_parser.chart:
|
||||
obbject.show()
|
||||
fig = obbject.chart.fig if obbject.chart else None
|
||||
else:
|
||||
if isinstance(df.columns, pd.RangeIndex):
|
||||
df.columns = [str(i) for i in df.columns]
|
||||
|
||||
print_rich_table(df=df, show_index=True, title=title)
|
||||
|
||||
elif isinstance(obbject, dict):
|
||||
df = pd.DataFrame.from_dict(obbject, orient="index")
|
||||
else:
|
||||
df = None
|
||||
df = pd.DataFrame.from_dict(obbject, orient="columns")
|
||||
print_rich_table(df=df, show_index=True, title=title)
|
||||
|
||||
elif hasattr(obbject, "to_dataframe"):
|
||||
df = obbject.to_dataframe()
|
||||
if isinstance(df.columns, pd.RangeIndex):
|
||||
df.columns = [str(i) for i in df.columns]
|
||||
print_rich_table(df=df, show_index=True, title=title)
|
||||
elif not isinstance(obbject, OBBject):
|
||||
session.console.print(obbject)
|
||||
|
||||
elif isinstance(obbject, dict):
|
||||
df = pd.DataFrame.from_dict(obbject, orient="index")
|
||||
print_rich_table(df=df, show_index=True, title=title)
|
||||
|
||||
elif obbject:
|
||||
session.console.print(obbject)
|
||||
|
||||
if hasattr(ns_parser, "export") and ns_parser.export:
|
||||
if (
|
||||
hasattr(ns_parser, "export")
|
||||
and ns_parser.export
|
||||
and not df.empty
|
||||
):
|
||||
sheet_name = getattr(ns_parser, "sheet_name", None)
|
||||
if sheet_name and isinstance(sheet_name, list):
|
||||
sheet_name = sheet_name[0]
|
||||
|
||||
export_data(
|
||||
export_type=",".join(ns_parser.export),
|
||||
dir_path=os.path.dirname(os.path.abspath(__file__)),
|
||||
@@ -209,11 +220,8 @@ class PlatformController(BaseController):
|
||||
sheet_name=sheet_name,
|
||||
figure=fig,
|
||||
)
|
||||
|
||||
if session.max_obbjects_exceeded():
|
||||
session.console.print(
|
||||
"[yellow]\nMaximum number of OBBjects reached. The oldest entry was removed.[yellow]"
|
||||
)
|
||||
elif hasattr(ns_parser, "export") and ns_parser.export and df.empty:
|
||||
session.console.print("[yellow]No data to export.[/yellow]")
|
||||
|
||||
except Exception as e:
|
||||
session.console.print(f"[red]{e}[/]\n")
|
||||
|
||||
Reference in New Issue
Block a user