mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-11-13 21:02:13 +00:00
fix package builder issues
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
# flake8: noqa
|
||||
from openbb_sdk.openbb_sdk_core.openbb_sdk_core.app.static.command_runner_wrapper import app
|
||||
|
||||
account = app.account
|
||||
from openbb_sdk.openbb_sdk_core.openbb_sdk_core.app.static.command_runner_wrapper import (
|
||||
app,
|
||||
)
|
||||
|
||||
@@ -148,7 +148,7 @@ class ImportDefinition:
|
||||
code += "\nimport pydantic"
|
||||
code += "\nfrom typing import List, Dict, Union, Optional, Literal"
|
||||
code += "\nimport warnings"
|
||||
code += "\nfrom builtin_extensions.common.utils import from_dataframe"
|
||||
code += "\nfrom openbb_sdk_core.app.utils import to_dataframe"
|
||||
code += "\nfrom openbb_sdk_core.app.model.abstract.warning import OpenBBWarning"
|
||||
|
||||
module_list = [hint_type.__module__ for hint_type in hint_type_list]
|
||||
|
||||
40
openbb_sdk/openbb_sdk_core/openbb_sdk_core/app/utils.py
Normal file
40
openbb_sdk/openbb_sdk_core/openbb_sdk_core/app/utils.py
Normal file
@@ -0,0 +1,40 @@
|
||||
from typing import List, Optional, Union
|
||||
|
||||
import pandas as pd
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
def to_dataframe(data: List[BaseModel], index: Optional[str] = None) -> pd.DataFrame:
|
||||
"""Convert to a Pandas DataFrame."""
|
||||
df = pd.DataFrame([d.dict() for d in data])
|
||||
if index and index in df.columns:
|
||||
df = df.set_index(index)
|
||||
return df
|
||||
|
||||
|
||||
def from_dataframe(
|
||||
df: Union[pd.DataFrame, pd.Series], index: bool = False
|
||||
) -> List[BaseModel]:
|
||||
"""Convert from a Pandas DataFrame."""
|
||||
if index:
|
||||
df = df.reset_index()
|
||||
if isinstance(df, pd.Series):
|
||||
df = df.to_frame()
|
||||
return [BaseModel(**d) for d in df.to_dict(orient="records")]
|
||||
|
||||
|
||||
def get_target_column(df: pd.DataFrame, target: str) -> pd.Series:
|
||||
"""Get target column from time series data."""
|
||||
if target not in df.columns:
|
||||
choices = ", ".join(df.columns)
|
||||
raise ValueError(
|
||||
f"Target column '{target}' not found in data. Choose from {choices}"
|
||||
)
|
||||
return df[target]
|
||||
|
||||
|
||||
def get_target_columns(df: pd.DataFrame, target_columns: List[str]) -> pd.DataFrame:
|
||||
df_result = pd.DataFrame()
|
||||
for target in target_columns:
|
||||
df_result[target] = get_target_column(df, target).to_frame()
|
||||
return df_result
|
||||
Reference in New Issue
Block a user