mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-12-01 13:44:16 +00:00
Handle dict of dicts
This commit is contained in:
@@ -156,6 +156,11 @@ class OBBject(GenericModel, Generic[T], Tagged):
|
||||
Dict[str, List]
|
||||
Dictionary of lists.
|
||||
"""
|
||||
if isinstance(self.results, dict) and all(
|
||||
isinstance(v, dict) for v in self.results.values()
|
||||
):
|
||||
return self.results
|
||||
|
||||
df = self.to_dataframe().reset_index() # type: ignore
|
||||
results = {}
|
||||
for field in df.columns:
|
||||
@@ -164,6 +169,7 @@ class OBBject(GenericModel, Generic[T], Tagged):
|
||||
# remove index from results
|
||||
if "index" in results:
|
||||
del results["index"]
|
||||
|
||||
return results
|
||||
|
||||
def to_chart(self, **kwargs):
|
||||
|
||||
@@ -263,11 +263,11 @@ def test_to_dataframe(results, expected_df):
|
||||
"4": {"x": 4, "y": 6},
|
||||
},
|
||||
{
|
||||
"0": [0, 2],
|
||||
"1": [1, 3],
|
||||
"2": [2, 0],
|
||||
"3": [3, 1],
|
||||
"4": [4, 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},
|
||||
},
|
||||
),
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user