mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-11-02 23:41:27 +00:00
Improve to_dict
This commit is contained in:
@@ -159,7 +159,14 @@ class OBBject(GenericModel, Generic[T], Tagged):
|
||||
if isinstance(self.results, dict) and all(
|
||||
isinstance(v, dict) for v in self.results.values()
|
||||
):
|
||||
return self.results
|
||||
results: Dict[str, List] = {}
|
||||
for _, v in self.results.items():
|
||||
for kk, vv in v.items():
|
||||
if kk not in results:
|
||||
results[kk] = []
|
||||
results[kk].append(vv)
|
||||
|
||||
return results
|
||||
|
||||
df = self.to_dataframe().reset_index() # type: ignore
|
||||
results = {}
|
||||
@@ -172,6 +179,12 @@ class OBBject(GenericModel, Generic[T], Tagged):
|
||||
|
||||
return results
|
||||
|
||||
# def to_dict(self, list_fields: bool = False) -> Dict[str, Any]:
|
||||
# if list_fields:
|
||||
# df = self.to_dataframe().reset_index()
|
||||
# return {field: df[field].tolist() for field in df.columns}
|
||||
# return self.dict()["results"]
|
||||
|
||||
def to_chart(self, **kwargs):
|
||||
"""
|
||||
Create or update the `Chart`.
|
||||
|
||||
@@ -262,13 +262,7 @@ def test_to_dataframe(results, expected_df):
|
||||
"3": {"x": 3, "y": 1},
|
||||
"4": {"x": 4, "y": 6},
|
||||
},
|
||||
{
|
||||
"0": {"x": 0, "y": 2},
|
||||
"1": {"x": 1, "y": 3},
|
||||
"2": {"x": 2, "y": 0},
|
||||
"3": {"x": 3, "y": 1},
|
||||
"4": {"x": 4, "y": 6},
|
||||
},
|
||||
{"x": [0, 1, 2, 3, 4], "y": [2, 3, 0, 1, 6]},
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user