Skip to content

Commit

Permalink
more flake fixes (#14)
Browse files Browse the repository at this point in the history
Co-authored-by: Markus Cozowicz <[email protected]>
  • Loading branch information
eisber and eisber authored Jun 17, 2024
1 parent 54ff9ad commit e785913
Show file tree
Hide file tree
Showing 40 changed files with 190 additions and 199 deletions.
5 changes: 4 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,7 @@ Repository = "https://github.com/microsoft/semantic-link-labs.git"

[[tool.mypy.overrides]]
module = "sempy.*,Microsoft.*,System.*,anytree.*,powerbiclient.*,synapse.ml.services.*"
ignore_missing_imports = true
ignore_missing_imports = true

[tool.flake8]
max-line-length = 200
4 changes: 2 additions & 2 deletions src/sempy_labs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@
resolve_dataset_name,
resolve_report_id,
resolve_report_name,
# language_validate
# language_validate
)
#from sempy_labs._model_auto_build import model_auto_build
# from sempy_labs._model_auto_build import model_auto_build
from sempy_labs._model_bpa import model_bpa_rules, run_model_bpa
from sempy_labs._model_dependencies import (
measure_dependency_tree,
Expand Down
7 changes: 4 additions & 3 deletions src/sempy_labs/_ai.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from IPython.display import display
import sempy_labs._icons as icons


def optimize_semantic_model(dataset: str, workspace: Optional[str] = None):

from ._model_bpa import run_model_bpa
Expand Down Expand Up @@ -92,7 +93,7 @@ def generate_measure_descriptions(
df = dfM_filt[["Table Name", "Measure Name", "Measure Expression"]]

df["prompt"] = (
f"The following is DAX code used by Microsoft Power BI. Please explain this code in simple terms:"
"The following is DAX code used by Microsoft Power BI. Please explain this code in simple terms:"
+ df["Measure Expression"]
)

Expand Down Expand Up @@ -152,11 +153,11 @@ def generate_aggs(
#'OrderDateKey': 'GroupBy'
# }

if workspace == None:
if workspace is None:
workspace_id = fabric.get_workspace_id()
workspace = fabric.resolve_workspace_name(workspace_id)

if lakehouse_workspace == None:
if lakehouse_workspace is None:
lakehouse_workspace = workspace
lakehouse_workspace_id = workspace_id
else:
Expand Down
2 changes: 1 addition & 1 deletion src/sempy_labs/_clear_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def clear_cache(dataset: str, workspace: Optional[str] = None):
or if no lakehouse attached, resolves to the workspace of the notebook.
"""

if workspace == None:
if workspace is None:
workspace_id = fabric.get_workspace_id()
workspace = fabric.resolve_workspace_name(workspace_id)

Expand Down
12 changes: 4 additions & 8 deletions src/sempy_labs/_dax.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ def evaluate_dax_impersonation(
The DAX query.
user_name : str
The user name (i.e. [email protected]).
Defaults to None which resolves to no user impersonation.
workspace : str, default=None
The Fabric workspace name.
Defaults to None which resolves to the workspace of the attached lakehouse
Expand All @@ -49,13 +48,10 @@ def evaluate_dax_impersonation(

dataset_id = resolve_dataset_id(dataset=dataset, workspace=workspace)

if user_name is None:
request_body = {"queries": [{"query": dax_query}]}
else:
request_body = {
"queries": [{"query": dax_query}],
"impersonatedUserName": user_name,
}
request_body = {
"queries": [{"query": dax_query}],
"impersonatedUserName": user_name
}

client = fabric.PowerBIRestClient()
response = client.post(
Expand Down
8 changes: 4 additions & 4 deletions src/sempy_labs/_generate_semantic_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def create_blank_semantic_model(
or if no lakehouse attached, resolves to the workspace of the notebook.
"""

if workspace == None:
if workspace is None:
workspace_id = fabric.get_workspace_id()
workspace = fabric.resolve_workspace_name(workspace_id)

Expand Down Expand Up @@ -178,11 +178,11 @@ def deploy_semantic_model(
"""

if workspace == None:
if workspace is None:
workspace_id = fabric.get_workspace_id()
workspace = fabric.resolve_workspace_name(workspace_id)

if new_dataset_workspace == None:
if new_dataset_workspace is None:
new_dataset_workspace = workspace

if new_dataset is None:
Expand Down Expand Up @@ -257,7 +257,7 @@ def get_semantic_model_bim(

if save_to_file_name is not None:
lakeAttach = lakehouse_attached()
if lakeAttach == False:
if lakeAttach is False:
print(
f"In order to save the model.bim file, a lakehouse must be attached to the notebook. Please attach a lakehouse to this notebook."
)
Expand Down
21 changes: 10 additions & 11 deletions src/sempy_labs/_helper_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def resolve_report_id(report: str, workspace: Optional[str] = None):
The ID of the Power BI report.
"""

if workspace == None:
if workspace is None:
workspace_id = fabric.get_workspace_id()
workspace = fabric.resolve_workspace_name(workspace_id)

Expand Down Expand Up @@ -129,7 +129,7 @@ def resolve_report_name(report_id: UUID, workspace: Optional[str] = None):
The name of the Power BI report.
"""

if workspace == None:
if workspace is None:
workspace_id = fabric.get_workspace_id()
workspace = fabric.resolve_workspace_name(workspace_id)

Expand Down Expand Up @@ -159,7 +159,7 @@ def resolve_dataset_id(dataset: str, workspace: Optional[str] = None):
The ID of the semantic model.
"""

if workspace == None:
if workspace is None:
workspace_id = fabric.get_workspace_id()
workspace = fabric.resolve_workspace_name(workspace_id)

Expand Down Expand Up @@ -189,7 +189,7 @@ def resolve_dataset_name(dataset_id: UUID, workspace: Optional[str] = None):
The name of the semantic model.
"""

if workspace == None:
if workspace is None:
workspace_id = fabric.get_workspace_id()
workspace = fabric.resolve_workspace_name(workspace_id)

Expand Down Expand Up @@ -220,7 +220,7 @@ def resolve_lakehouse_name(lakehouse_id: Optional[UUID] = None, workspace: Optio
The name of the Fabric lakehouse.
"""

if workspace == None:
if workspace is None:
workspace_id = fabric.get_workspace_id()
workspace = fabric.resolve_workspace_name(workspace_id)

Expand Down Expand Up @@ -253,7 +253,7 @@ def resolve_lakehouse_id(lakehouse: str, workspace: Optional[str] = None):
The ID of the Fabric lakehouse.
"""

if workspace == None:
if workspace is None:
workspace_id = fabric.get_workspace_id()
workspace = fabric.resolve_workspace_name(workspace_id)

Expand Down Expand Up @@ -283,18 +283,17 @@ def get_direct_lake_sql_endpoint(dataset: str, workspace: Optional[str] = None)
The ID of SQL Endpoint.
"""

if workspace == None:
if workspace is None:
workspace_id = fabric.get_workspace_id()
workspace = fabric.resolve_workspace_name(workspace_id)

dfP = fabric.list_partitions(dataset=dataset, workspace=workspace)
dfP_filt = dfP[dfP["Mode"] == "DirectLake"]

if len(dfP_filt) == 0:
print(
raise ValueError(
f"The '{dataset}' semantic model in the '{workspace}' workspace is not in Direct Lake mode."
)
return

dfE = fabric.list_expressions(dataset=dataset, workspace=workspace)
dfE_filt = dfE[dfE["Name"] == "DatabaseQuery"]
Expand Down Expand Up @@ -502,10 +501,10 @@ def resolve_workspace_name_and_id(workspace: Optional[str] = None) -> Tuple[str,
The name and ID of the Fabric workspace.
"""

if workspace == None:
if workspace is None:
workspace_id = fabric.get_workspace_id()
workspace = fabric.resolve_workspace_name(workspace_id)
else:
workspace_id = fabric.resolve_workspace_id(workspace)

return workspace, workspace_id
return str(workspace), str(workspace_id)
29 changes: 14 additions & 15 deletions src/sempy_labs/_list_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def get_object_level_security(dataset: str, workspace: Optional[str] = None):
A pandas dataframe showing the object level security for the semantic model.
"""

if workspace == None:
if workspace is None:
workspace_id = fabric.get_workspace_id()
workspace = fabric.resolve_workspace_name(workspace_id)

Expand Down Expand Up @@ -88,7 +88,7 @@ def list_tables(dataset: str, workspace: Optional[str] = None):
A pandas dataframe showing the semantic model's tables and their properties.
"""

if workspace == None:
if workspace is None:
workspace_id = fabric.get_workspace_id()
workspace = fabric.resolve_workspace_name(workspace_id)

Expand Down Expand Up @@ -154,7 +154,7 @@ def list_annotations(dataset: str, workspace: Optional[str] = None):
A pandas dataframe showing the semantic model's annotations and their properties.
"""

if workspace == None:
if workspace is None:
workspace_id = fabric.get_workspace_id()
workspace = fabric.resolve_workspace_name(workspace_id)

Expand Down Expand Up @@ -384,7 +384,7 @@ def list_columns(
get_direct_lake_lakehouse,
)

if workspace == None:
if workspace is None:
workspace_id = fabric.get_workspace_id()
workspace = fabric.resolve_workspace_name(workspace_id)

Expand Down Expand Up @@ -1032,10 +1032,10 @@ def create_warehouse(

(workspace, workspace_id) = resolve_workspace_name_and_id(workspace)

if description == None:
request_body = {"displayName": warehouse}
else:
request_body = {"displayName": warehouse, "description": description}
request_body = {"displayName": warehouse}

if description:
request_body["description"] = description

client = fabric.FabricRestClient()
response = client.post(
Expand Down Expand Up @@ -1123,18 +1123,17 @@ def update_item(

itemId = dfI_filt["Id"].iloc[0]

if description == None:
request_body = {"displayName": new_name}
else:
request_body = {"displayName": new_name, "description": description}
request_body = {"displayName": new_name}
if description:
request_body["description"] = description

client = fabric.FabricRestClient()
response = client.patch(
f"/v1/workspaces/{workspace_id}/{itemType}/{itemId}", json=request_body
)

if response.status_code == 200:
if description == None:
if description is None:
print(
f"The '{current_name}' {item_type} within the '{workspace}' workspace has been updated to be named '{new_name}'"
)
Expand Down Expand Up @@ -1171,7 +1170,7 @@ def list_relationships(
A pandas dataframe showing the object level security for the semantic model.
"""

if workspace == None:
if workspace is None:
workspace_id = fabric.get_workspace_id()
workspace = fabric.resolve_workspace_name(workspace_id)

Expand Down Expand Up @@ -1560,7 +1559,7 @@ def list_shortcuts(

(workspace, workspace_id) = resolve_workspace_name_and_id(workspace)

if lakehouse == None:
if lakehouse is None:
lakehouse_id = fabric.get_lakehouse_id()
lakehouse = resolve_lakehouse_name(lakehouse_id, workspace)
else:
Expand Down
Loading

0 comments on commit e785913

Please sign in to comment.