From 0edf9b3e225ec4a42a406dfc53e2208915a837d2 Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 1 Oct 2024 14:20:48 +0200 Subject: [PATCH] fixed up changes per merge --- src/sempy_labs/_helper_functions.py | 14 +++++++--- src/sempy_labs/_model_dependencies.py | 16 ++++++++--- src/sempy_labs/report/_report_bpa.py | 8 +++--- src/sempy_labs/tom/_model.py | 39 +++++++++++++++++++++++++-- 4 files changed, 64 insertions(+), 13 deletions(-) diff --git a/src/sempy_labs/_helper_functions.py b/src/sempy_labs/_helper_functions.py index bcddae20..1f227157 100644 --- a/src/sempy_labs/_helper_functions.py +++ b/src/sempy_labs/_helper_functions.py @@ -999,7 +999,9 @@ def resolve_warehouse_id(warehouse: str, workspace: Optional[str]) -> UUID: """ workspace = fabric.resolve_workspace_name(workspace) - return fabric.resolve_item_id(item_name=warehouse, type='Warehouse', workspace=workspace) + return fabric.resolve_item_id( + item_name=warehouse, type="Warehouse", workspace=workspace + ) def get_language_codes(languages: str | List[str]): @@ -1048,7 +1050,7 @@ def get_azure_token_credentials( def convert_to_alphanumeric_lowercase(input_string): - # Removes non-alphanumeric characters + # Removes non-alphanumeric characters cleaned_string = re.sub(r"[^a-zA-Z0-9]", "", input_string) cleaned_string = cleaned_string.lower() @@ -1071,7 +1073,9 @@ def resolve_environment_id(environment: str, workspace: Optional[str] = None) -> """ workspace = fabric.resolve_workspace_name(workspace) - return fabric.resolve_item_id(item_name=environment, type='Environment', workspace=workspace) + return fabric.resolve_item_id( + item_name=environment, type="Environment", workspace=workspace + ) def make_clickable(val): @@ -1119,7 +1123,9 @@ def resolve_notebook_id(notebook: str, workspace: Optional[str] = None) -> UUID: """ workspace = fabric.resolve_workspace_name(workspace) - return fabric.resolve_item_id(item_name=notebook, type='Notebook', workspace=workspace) + return fabric.resolve_item_id( + item_name=notebook, type="Notebook", workspace=workspace + ) def generate_guid(): diff --git a/src/sempy_labs/_model_dependencies.py b/src/sempy_labs/_model_dependencies.py index 2927c078..6eb77a8c 100644 --- a/src/sempy_labs/_model_dependencies.py +++ b/src/sempy_labs/_model_dependencies.py @@ -87,7 +87,9 @@ def get_measure_dependencies( "Object Type": r["Object Type"], "Referenced Object": dependency.iloc[4], "Referenced Table": dependency.iloc[3], - "Referenced Object Type": dependency.iloc[5], + "Referenced Object Type": dependency.iloc[ + 5 + ], "Done": d, "Full Object Name": r["Full Object Name"], "Referenced Full Object Name": dependency.iloc[ @@ -112,7 +114,9 @@ def get_measure_dependencies( "Object Type": r["Object Type"], "Referenced Object": dependency.iloc[4], "Referenced Table": dependency.iloc[3], - "Referenced Object Type": dependency.iloc[5], + "Referenced Object Type": dependency.iloc[ + 5 + ], "Done": d, "Full Object Name": r["Full Object Name"], "Referenced Full Object Name": dependency.iloc[ @@ -216,7 +220,9 @@ def get_model_calc_dependencies( "Object Type": r["Object Type"], "Referenced Object": dependency.iloc[4], "Referenced Table": dependency.iloc[3], - "Referenced Object Type": dependency.iloc[5], + "Referenced Object Type": dependency.iloc[ + 5 + ], "Done": d, "Full Object Name": r["Full Object Name"], "Referenced Full Object Name": dependency.iloc[ @@ -241,7 +247,9 @@ def get_model_calc_dependencies( "Object Type": r["Object Type"], "Referenced Object": dependency.iloc[5], "Referenced Table": dependency.iloc[4], - "Referenced Object Type": dependency.iloc[6], + "Referenced Object Type": dependency.iloc[ + 6 + ], "Done": d, "Full Object Name": r["Full Object Name"], "Referenced Full Object Name": dependency.iloc[ diff --git a/src/sempy_labs/report/_report_bpa.py b/src/sempy_labs/report/_report_bpa.py index 37357493..f5f1159b 100644 --- a/src/sempy_labs/report/_report_bpa.py +++ b/src/sempy_labs/report/_report_bpa.py @@ -60,9 +60,9 @@ def run_report_bpa( ) dfPF = rpt.list_page_filters() # Convert back to dataframe - #if isinstance(dfPF, pd.io.formats.style.Styler): + # if isinstance(dfPF, pd.io.formats.style.Styler): # dfPF = dfPF.data - #if isinstance(dfP, pd.io.formats.style.Styler): + # if isinstance(dfP, pd.io.formats.style.Styler): # dfP = dfP.data dfPF["Filter Object"] = ( @@ -142,7 +142,9 @@ def execute_rule(row): df_output["Severity"] = row["Severity"] df_output["Description"] = row["Description"] df_output["URL"] = row["URL"] - df_output["Report URL"] = helper.get_web_url(report=report, workspace=workspace) + df_output["Report URL"] = helper.get_web_url( + report=report, workspace=workspace + ) page_mapping_dict = dfP.set_index("Page Display Name")["Page URL"].to_dict() diff --git a/src/sempy_labs/tom/_model.py b/src/sempy_labs/tom/_model.py index e9514001..1aa7c340 100644 --- a/src/sempy_labs/tom/_model.py +++ b/src/sempy_labs/tom/_model.py @@ -4248,6 +4248,37 @@ def is_calculated_table(self, table_name: str): isCalcTable = True return isCalcTable + def update_lineage_tags(self): + """ + Adds lineage and source lineage tags for relevant semantic model objects if they do not exist. + """ + + for t in self.model.Tables: + if len(t.LineageTag) == 0: + t.LineageTag = generate_guid() + if len(t.SourceLineageTag) == 0: + t.SourceLineageTag = generate_guid() + for c in self.all_columns(): + if len(c.LineageTag) == 0: + c.LineageTag = generate_guid() + if len(c.SourceLineageTag) == 0: + c.SourceLineageTag = generate_guid() + for m in self.all_measures(): + if len(m.LineageTag) == 0: + m.LineageTag = generate_guid() + if len(m.SourceLineageTag) == 0: + m.SourceLineageTag = generate_guid() + for h in self.all_hierarchies(): + if len(h.LineageTag) == 0: + h.LineageTag = generate_guid() + if len(h.SourceLineageTag) == 0: + h.SourceLineageTag = generate_guid() + for lvl in self.all_levels(): + if len(lvl.LineageTag) == 0: + lvl.LineageTag = generate_guid() + if len(h.SourceLineageTag) == 0: + h.SourceLineageTag = generate_guid() + def generate_measure_descriptions( self, measure_name: Optional[str | List[str]] = None, @@ -4294,10 +4325,14 @@ def generate_measure_descriptions( } for m_name in measure_list: expr, t_name = next( - (ms.Expression, ms.Parent.Name) for ms in self.all_measures() if ms.Name == m_name + (ms.Expression, ms.Parent.Name) + for ms in self.all_measures() + if ms.Name == m_name ) if t_name is None: - raise ValueError(f"{icons.red_dot} The '{m_name}' measure does not exist in the '{self._dataset}' semantic model within the '{self._workspace}' workspace.") + raise ValueError( + f"{icons.red_dot} The '{m_name}' measure does not exist in the '{self._dataset}' semantic model within the '{self._workspace}' workspace." + ) new_item = { "urn": m_name,