-
Notifications
You must be signed in to change notification settings - Fork 173
1168 #1169
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
1168 #1169
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -13,6 +13,7 @@ | |||
| _get_column_aggregate, | ||||
| resolve_workspace_name_and_id, | ||||
| resolve_dataset_name_and_id, | ||||
| _update_dataframe_datatypes, | ||||
| ) | ||||
| from sempy_labs.lakehouse._get_lakehouse_tables import get_lakehouse_tables | ||||
| from typing import Optional, Literal | ||||
|
|
@@ -970,6 +971,32 @@ def create_dfs(column_formatting: str = "format"): | |||
| } | ||||
| return dfs | ||||
|
|
||||
| # Prepare output for returned dictionary of dataframes and for exported dataframes | ||||
| dtype_map = {"string": "string", "long": "int", "double": "float", "bool": "bool"} | ||||
| return_sections = { | ||||
| "Model": "Model Summary", | ||||
| "Tables": "Tables", | ||||
| "Partitions": "Partitions", | ||||
| "Columns": "Columns", | ||||
| "Relationships": "Relationships", | ||||
| "Hierarchies": "Hierarchies", | ||||
| } | ||||
| final_dict = {} | ||||
| for name, title in return_sections.items(): | ||||
| items = config[name] | ||||
| data = items.get("data") | ||||
| sort_col = items.get("sortby") | ||||
| df = pd.DataFrame(data, columns=list(vertipaq_map[name].keys())) | ||||
| if sort_col and sort_col in df.columns: | ||||
| df = df.sort_values(by=sort_col, ascending=False).reset_index(drop=True) | ||||
| col_types = { | ||||
| k: dtype_map.get(v["data_type"], "string") | ||||
| for k, v in vertipaq_map[name].items() | ||||
| if k in df.columns | ||||
| } | ||||
| _update_dataframe_datatypes(df, col_types) | ||||
| final_dict[title] = df | ||||
|
|
||||
|
Comment on lines
+974
to
+999
|
||||
| if export is None: | ||||
| dfs = create_dfs(column_formatting="format") | ||||
| default_sort = { | ||||
|
|
@@ -978,18 +1005,12 @@ def create_dfs(column_formatting: str = "format"): | |||
| if items.get("sortby") | ||||
| } | ||||
| visualize_vertipaq(dfs, dataset_name, vertipaq_map, default_sort=default_sort) | ||||
| return { | ||||
| "Model Summary": dfs["Model"]["data"], | ||||
| "Tables": dfs["Tables"]["data"], | ||||
| "Partitions": dfs["Partitions"]["data"], | ||||
| "Columns": dfs["Columns"]["data"], | ||||
| "Relationships": dfs["Relationships"]["data"], | ||||
| "Hierarchies": dfs["Hierarchies"]["data"], | ||||
| } | ||||
|
|
||||
| return final_dict | ||||
|
|
||||
| # Export vertipaq to delta tables in lakehouse | ||||
| if export == "table": | ||||
| dfs = create_dfs(column_formatting="data_type") | ||||
| #dfs = create_dfs(column_formatting="data_type") | ||||
|
|
||||
|
Comment on lines
+1013
to
1014
|
||||
| #dfs = create_dfs(column_formatting="data_type") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the
export is Nonepath, the code now builds DataFrames twice: once in the newfinal_dictloop and again increate_dfs()for visualization. For large models (especially the Columns section) this doubles DataFrame construction/sorting work. Consider deriving the returned DataFrames from the already-builtdfs(or vice-versa) by copying before formatting, so the raw-typed and display-formatted outputs share the same underlying DataFrame build/cleanup steps.