Skip to content

Commit 80fd83c

Browse files
committed
black + gen dl
1 parent 9c23a02 commit 80fd83c

File tree

6 files changed

+55
-26
lines changed

6 files changed

+55
-26
lines changed

src/sempy_labs/directlake/_dl_helper.py

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import sempy_labs._icons as icons
77
from sempy._utils._log import log
88
from sempy_labs._helper_functions import (
9+
resolve_lakehouse_name_and_id,
910
retry,
1011
_convert_data_type,
1112
resolve_dataset_name_and_id,
@@ -83,7 +84,7 @@ def generate_direct_lake_semantic_model(
8384
workspace: Optional[str | UUID] = None,
8485
lakehouse: Optional[str] = None,
8586
lakehouse_workspace: Optional[str | UUID] = None,
86-
schema: str = "dbo",
87+
schema: Optional[str] = None,
8788
overwrite: bool = False,
8889
refresh: bool = True,
8990
):
@@ -107,7 +108,7 @@ def generate_direct_lake_semantic_model(
107108
The Fabric workspace name or ID in which the lakehouse resides.
108109
Defaults to None which resolves to the workspace of the attached lakehouse
109110
or if no lakehouse attached, resolves to the workspace of the notebook.
110-
schema : str, default="dbo"
111+
schema : str, default=None
111112
The schema used for the lakehouse.
112113
overwrite : bool, default=False
113114
If set to True, overwrites the existing semantic model if it already exists.
@@ -127,10 +128,16 @@ def generate_direct_lake_semantic_model(
127128
lakehouse_tables = [lakehouse_tables]
128129

129130
(workspace_name, workspace_id) = resolve_workspace_name_and_id(workspace)
130-
if lakehouse_workspace is None:
131-
lakehouse_workspace = workspace
131+
(lakehouse_workspace_name, lakehouse_workspace_id) = resolve_workspace_name_and_id(
132+
lakehouse_workspace
133+
)
134+
(lakehouse_name, lakehouse_id) = resolve_lakehouse_name_and_id(
135+
lakehouse, lakehouse_workspace_id
136+
)
132137

133-
dfLT = get_lakehouse_tables(lakehouse=lakehouse, workspace=lakehouse_workspace)
138+
dfLT = get_lakehouse_tables(
139+
lakehouse=lakehouse_id, workspace=lakehouse_workspace_id
140+
)
134141

135142
icons.sll_tags.append("GenerateDLModel")
136143

@@ -141,9 +148,9 @@ def generate_direct_lake_semantic_model(
141148
f"{icons.red_dot} The '{t}' table does not exist as a delta table in the '{lakehouse}' within the '{workspace_name}' workspace."
142149
)
143150

144-
dfLC = get_lakehouse_columns(lakehouse=lakehouse, workspace=lakehouse_workspace)
151+
dfLC = get_lakehouse_columns(lakehouse=lakehouse, workspace=lakehouse_workspace_id)
145152
expr = generate_shared_expression(
146-
item_name=lakehouse, item_type="Lakehouse", workspace=lakehouse_workspace
153+
item_name=lakehouse, item_type="Lakehouse", workspace=lakehouse_workspace_id
147154
)
148155
dfD = fabric.list_datasets(workspace=workspace_id, mode="rest")
149156
dfD_filt = dfD[dfD["Dataset Name"] == dataset]
@@ -179,9 +186,17 @@ def dyn_connect():
179186

180187
for t in lakehouse_tables:
181188
tom.add_table(name=t)
182-
tom.add_entity_partition(table_name=t, entity_name=t, schema_name=schema)
189+
tom.add_entity_partition(
190+
table_name=t, entity_name=t, schema_name=schema or "dbo"
191+
)
183192
dfLC_filt = dfLC[dfLC["Table Name"] == t]
184-
for i, r in dfLC_filt.iterrows():
193+
if schema:
194+
dfLC_filt = dfLC_filt[dfLC_filt["Schema Name"] == schema]
195+
if dfLC_filt.empty:
196+
raise ValueError(
197+
f"{icons.red_dot} No columns found for the '{t}' table in the '{lakehouse_name}' lakehouse. Please ensure the table has columns and if a schema is provided, that the schema name is correct."
198+
)
199+
for _, r in dfLC_filt.iterrows():
185200
lakeCName = r["Column Name"]
186201
dType = r["Data Type"]
187202
dt = _convert_data_type(dType)

src/sempy_labs/directlake/_update_directlake_partition_entity.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,7 @@ def update_direct_lake_partition_entity(
8686
# Update source lineage tag
8787
if schema:
8888
# Updated to all DL patterns (DLOL, DLSQL)
89-
tom.model.Tables[tName].Partitions[
90-
part_name
91-
].Source.SchemaName = schema
89+
tom.model.Tables[tName].Partitions[part_name].Source.SchemaName = schema
9290
tom.model.Tables[tName].SourceLineageTag = f"[{schema}].[{eName}]"
9391
else:
9492
tom.model.Tables[tName].SourceLineageTag = f"[dbo].[{eName}]"

src/sempy_labs/lakehouse/_get_lakehouse_columns.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def add_column_metadata(table_name, schema_name, col_name, data_type):
7878

7979
for _, r in tables_filt.iterrows():
8080
table_name = r["Table Name"]
81-
schema_name = r['Schema Name']
81+
schema_name = r["Schema Name"]
8282
path = r["Location"]
8383

8484
if _pure_python_notebook():

src/sempy_labs/report/_reportwrapper.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,11 @@ def __init__(
100100
self._show_diffs = show_diffs
101101

102102
# Check that the report is in the PBIR format.
103-
response = _base_api(request=f"/v1.0/myorg/groups/{self._workspace_id}/reports/{self._report_id}", client="fabric_sp")
104-
self.format = response.json().get('format')
103+
response = _base_api(
104+
request=f"/v1.0/myorg/groups/{self._workspace_id}/reports/{self._report_id}",
105+
client="fabric_sp",
106+
)
107+
self.format = response.json().get("format")
105108

106109
result = _base_api(
107110
request=f"/v1/workspaces/{self._workspace_id}/items/{self._report_id}/getDefinition",

src/sempy_labs/semantic_model/_caching.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212

1313
@log
1414
def enable_query_caching(
15-
dataset: str | UUID, workspace: Optional[str | UUID] = None, enable: bool = True,
15+
dataset: str | UUID,
16+
workspace: Optional[str | UUID] = None,
17+
enable: bool = True,
1618
):
1719
"""
1820
Enables or disables `query caching <http://aka.ms/queryCaching>`_ for a semantic model.
@@ -35,7 +37,9 @@ def enable_query_caching(
3537
)
3638
model_id = get_model_id(item_id=item_id)
3739
if model_id is None:
38-
raise ValueError(f"Failed to retrieve model ID for semantic model '{item_name}'")
40+
raise ValueError(
41+
f"Failed to retrieve model ID for semantic model '{item_name}'"
42+
)
3943

4044
caching_map = {
4145
True: 2,
@@ -44,7 +48,12 @@ def enable_query_caching(
4448

4549
payload = {"queryCachingState": caching_map.get(enable)}
4650

47-
_base_api(request=f"metadata/models/{model_id}/caching", method="internal", payload=payload, status_codes=204)
51+
_base_api(
52+
request=f"metadata/models/{model_id}/caching",
53+
method="internal",
54+
payload=payload,
55+
status_codes=204,
56+
)
4857

4958
print(
5059
f"{icons.green_dot} Query caching has been {'enabled' if enable else 'disabled'} for the '{item_name}' semantic model within the '{workspace_name}' workspace."

src/sempy_labs/surge_protection/_items.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,17 @@
1010
from sempy._utils._log import log
1111

1212

13-
def _surge_api(
14-
capacity, url, payload, method="get", status_code=200, return_json=True
15-
):
13+
def _surge_api(capacity, url, payload, method="get", status_code=200, return_json=True):
1614

1715
capacity_id = resolve_capacity_id(capacity)
1816

19-
response = _base_api(request=f"capacities/{capacity_id}/{url}", client="internal", method=method, payload=payload, status_codes=status_code)
17+
response = _base_api(
18+
request=f"capacities/{capacity_id}/{url}",
19+
client="internal",
20+
method=method,
21+
payload=payload,
22+
status_codes=status_code,
23+
)
2024

2125
if return_json:
2226
return response.json()
@@ -48,9 +52,7 @@ def get_workspace_consumption_rules(
4852
or a dictionary if return_dataframe is set to False.
4953
"""
5054

51-
response_json = _surge_api(
52-
capacity=capacity, url="detectionRules", payload=None
53-
)
55+
response_json = _surge_api(capacity=capacity, url="detectionRules", payload=None)
5456

5557
if not return_dataframe:
5658
return response_json
@@ -347,4 +349,6 @@ def delete_background_operation_rules(capacity: str | UUID = None):
347349
return_json=False,
348350
)
349351

350-
print(f"{icons.green_dot} The background operation rules have been deleted successfully.")
352+
print(
353+
f"{icons.green_dot} The background operation rules have been deleted successfully."
354+
)

0 commit comments

Comments
 (0)