diff options
author | Danglewood <85772166+deeleeramone@users.noreply.github.com> | 2024-06-28 16:39:01 -0700 |
---|---|---|
committer | Danglewood <85772166+deeleeramone@users.noreply.github.com> | 2024-06-28 16:39:01 -0700 |
commit | ea8030b0b85affd9fc1cc8278b9563ab59cd36f6 (patch) | |
tree | 57d460c0e2ed85b4f9b852ba6e3d665a2b912c98 | |
parent | 40b2d3d3160f174da855cc7293f4ad0926f160ab (diff) |
exclude None and unset from basemodel_to_df
-rw-r--r-- | openbb_platform/core/openbb_core/app/utils.py | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/openbb_platform/core/openbb_core/app/utils.py b/openbb_platform/core/openbb_core/app/utils.py index 452300c4334..366fcb6e447 100644 --- a/openbb_platform/core/openbb_core/app/utils.py +++ b/openbb_platform/core/openbb_core/app/utils.py @@ -21,12 +21,16 @@ def basemodel_to_df( ) -> pd.DataFrame: """Convert list of BaseModel to a Pandas DataFrame.""" if isinstance(data, list): - df = pd.DataFrame([d.model_dump() for d in data]) + df = pd.DataFrame( + [d.model_dump(exclude_none=True, exclude_unset=True) for d in data] + ) else: try: - df = pd.DataFrame(data.model_dump()) + df = pd.DataFrame(data.model_dump(exclude_none=True, exclude_unset=True)) except ValueError: - df = pd.DataFrame(data.model_dump(), index=["values"]) + df = pd.DataFrame( + data.model_dump(exclude_none=True, exclude_unset=True), index=["values"] + ) if "is_multiindex" in df.columns: col_names = ast.literal_eval(df.multiindex_names.unique()[0]) |