Skip to content

Commit 09012bf

Browse files
author
jkasiraj
committed
improve formatting and name conventions in query.py
1 parent 8cd1913 commit 09012bf

File tree

1 file changed

+30
-18
lines changed

1 file changed

+30
-18
lines changed

src/sagemaker/lineage/query.py

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ def __str__(self):
9999
100100
Format:
101101
{
102-
'source_arn': 'string', 'destination_arn': 'string',
102+
'source_arn': 'string',
103+
'destination_arn': 'string',
103104
'association_type': 'string'
104105
}
105106
@@ -111,7 +112,8 @@ def __repr__(self):
111112
112113
Format:
113114
{
114-
'source_arn': 'string', 'destination_arn': 'string',
115+
'source_arn': 'string',
116+
'destination_arn': 'string',
115117
'association_type': 'string'
116118
}
117119
@@ -161,7 +163,8 @@ def __str__(self):
161163
162164
Format:
163165
{
164-
'arn': 'string', 'lineage_entity': 'string',
166+
'arn': 'string',
167+
'lineage_entity': 'string',
165168
'lineage_source': 'string',
166169
'_session': <sagemaker.session.Session object>
167170
}
@@ -174,7 +177,8 @@ def __repr__(self):
174177
175178
Format:
176179
{
177-
'arn': 'string', 'lineage_entity': 'string',
180+
'arn': 'string',
181+
'lineage_entity': 'string',
178182
'lineage_source': 'string',
179183
'_session': <sagemaker.session.Session object>
180184
}
@@ -238,7 +242,7 @@ def __init__(self, graph_styles):
238242
graph_styles: A dictionary that contains graph style for node and edges by their type.
239243
Example: Display the nodes with different color by their lineage entity / different
240244
shape by start arn.
241-
lineage_graph = {
245+
lineage_graph_styles = {
242246
"TrialComponent": {
243247
"name": "Trial Component",
244248
"style": {"background-color": "#f6cf61"},
@@ -253,7 +257,7 @@ def __init__(self, graph_styles):
253257
"name": "StartArn",
254258
"style": {"shape": "star"},
255259
"isShape": "True",
256-
"symbol": "★", # shape symbol for legend
260+
"symbol": "★", # shape symbol for legend
257261
},
258262
}
259263
@@ -297,7 +301,7 @@ def __init__(self, graph_styles):
297301
"solver": "hierarchicalRepulsion"
298302
}
299303
}
300-
"""
304+
"""
301305

302306
def _import_visual_modules(self):
303307
"""Import modules needed for visualization."""
@@ -358,7 +362,7 @@ def _add_legend(self, path):
358362
with open(path, "w", encoding="utf8") as file:
359363
file.write(html)
360364

361-
def render(self, elements, path="pyvisExample.html"):
365+
def render(self, elements, path="lineage_graph_pyvis.html.html"):
362366
"""Render graph for lineage query result.
363367
364368
Args:
@@ -370,7 +374,7 @@ def render(self, elements, path="pyvisExample.html"):
370374
elements["edges"] contains list of tuples, each tuple represents an edge
371375
format: (edge source arn, edge destination arn, edge association type)
372376
373-
path(optional): The path/filemname of the rendered graph html file. (default path: "pyvisExample.html")
377+
path(optional): The path/filename of the rendered graph html file. (default path: "lineage_graph_pyvis.html.html")
374378
375379
Returns:
376380
display graph: The interactive visualization is presented as a static HTML file.
@@ -457,13 +461,21 @@ def __str__(self):
457461
Format:
458462
{
459463
'edges':[
460-
{'source_arn': 'string', 'destination_arn': 'string', 'association_type': 'string'},
461-
...],
464+
{
465+
'source_arn': 'string',
466+
'destination_arn': 'string',
467+
'association_type': 'string'
468+
},
469+
],
462470
463471
'vertices':[
464-
{'arn': 'string', 'lineage_entity': 'string', 'lineage_source': 'string',
465-
'_session': <sagemaker.session.Session object>},
466-
...],
472+
{
473+
'arn': 'string',
474+
'lineage_entity': 'string',
475+
'lineage_source': 'string',
476+
'_session': <sagemaker.session.Session object>
477+
},
478+
],
467479
468480
'startarn':['string', ...]
469481
}
@@ -503,7 +515,7 @@ def _get_visualization_elements(self):
503515
elements = {"nodes": verts, "edges": edges}
504516
return elements
505517

506-
def visualize(self, path="pyvisExample.html"):
518+
def visualize(self, path: Optional[str] = "lineage_graph_pyvis.html.html"):
507519
"""Visualize lineage query result.
508520
509521
Creates a PyvisVisualizer object to render network graph with Pyvis library.
@@ -512,12 +524,12 @@ def visualize(self, path="pyvisExample.html"):
512524
PyvisVisualizer for rendering graph.
513525
514526
Args:
515-
path(optional): The path/filemname of the rendered graph html file. (default path: "pyvisExample.html")
527+
path(optional): The path/filemname of the rendered graph html file. (default path: "lineage_graph_pyvis.html.html")
516528
517529
Returns:
518530
display graph: The interactive visualization is presented as a static HTML file.
519531
"""
520-
lineage_graph = {
532+
lineage_graph_styles = {
521533
# nodes can have shape / color
522534
"TrialComponent": {
523535
"name": "Trial Component",
@@ -547,7 +559,7 @@ def visualize(self, path="pyvisExample.html"):
547559
},
548560
}
549561

550-
pyvis_vis = PyvisVisualizer(lineage_graph)
562+
pyvis_vis = PyvisVisualizer(lineage_graph_styles)
551563
elements = self._get_visualization_elements()
552564
return pyvis_vis.render(elements=elements, path=path)
553565

0 commit comments

Comments
 (0)