Handle dict of dicts

This commit is contained in:
Igor Radovanovic
2023-09-11 22:24:46 +02:00
parent b7d1272a84
commit 969b0262bd
2 changed files with 11 additions and 5 deletions

View File

@@ -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):

View File

@@ -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},
},
),
],