Skip to content

Commit

Permalink
Print useful information for commonly used objects. (#167)
Browse files Browse the repository at this point in the history
  • Loading branch information
siyuan0322 authored Mar 1, 2021
1 parent 70bb6e5 commit 5b5061d
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 19 deletions.
6 changes: 6 additions & 0 deletions python/graphscope/experimental/nx/classes/digraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,12 @@ def __init__(self, incoming_graph_data=None, **attr):
self.graph.update(attr)
self._saved_signature = self.signature

def __repr__(self):
s = "graphscope.nx.DiGraph\n"
s += "type: " + self.template_str.split("<")[0]
s += str(self._schema)
return s

@property
def adj(self):
"""Graph adjacency object holding the successors of each node.
Expand Down
6 changes: 6 additions & 0 deletions python/graphscope/experimental/nx/classes/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,12 @@ def __str__(self):
"""
return self.name

def __repr__(self):
s = "graphscope.nx.Graph\n"
s += "type: " + self.template_str.split("<")[0]
s += str(self._schema)
return s

def __copy__(self):
raise NetworkXError("not support shallow copy.")

Expand Down
7 changes: 6 additions & 1 deletion python/graphscope/framework/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ def __init__(self, algo, gar=None, **kwargs):
# built_in apps has no gar resource.
self._gar = None

def __repr__(self) -> str:
return f"graphscope.AppAssets <type: {self._type}, algorithm: {self._algo}>"

@property
def algo(self):
"""Algorithm name, e.g. sssp, pagerank.
Expand Down Expand Up @@ -268,7 +271,9 @@ class name.
self._saved_signature = self.signature

def __repr__(self):
return "<graphscope.App '%s'>" % self.key
s = f"graphscope.App <type: {self._app_assets.type}, algorithm: {self._app_assets.algo}"
s += f"bounded_graph: {str(self._graph)}>"
return s

@property
def key(self):
Expand Down
3 changes: 3 additions & 0 deletions python/graphscope/framework/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ def __init__(self, session_id, context_key, graph):
self._session_id = session_id
self._saved_signature = self.signature

def __repr__(self):
return f"graphscope.{self.__class__.__name__} from graph {str(self._graph)}"

@property
def key(self):
"""Unique identifier of a context."""
Expand Down
5 changes: 4 additions & 1 deletion python/graphscope/framework/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,11 @@ def detach(self):
def loaded(self):
return self._key is not None

def __str__(self):
return f"graphscope.Graph {self.template_str}"

def __repr__(self):
return "<grape.Graph '%s'>" % self._key
return f"graphscope.Graph\ntype: {self.template_str.split('<')[0]}\n\n{str(self._schema)}"

def unload(self):
"""Unload this graph from graphscope engine."""
Expand Down
24 changes: 7 additions & 17 deletions python/graphscope/framework/graph_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,29 +124,19 @@ def init_nx_schema(self, gs_schema=None):
self._edge_relationships.append([("_", "_")])

def __repr__(self):
s = "oid_type: {}\nvid_type: {}\n".format(self._oid_type, self._vid_type)
s = f"oid_type: {self._oid_type}\nvid_type: {self._vid_type}\n"
if (
self._vdata_type != types_pb2.INVALID
and self._edata_type != types_pb2.INVALID
):
s += "vdata_type: {}\nedata_type: {}\n".format(
types_pb2.DataType.Name(self._vdata_type),
types_pb2.DataType.Name(self._edata_type),
)
s += f"vdata_type: {types_pb2.DataType.Name(self._vdata_type)}\n"
s += f"edata_type: {types_pb2.DataType.Name(self._edata_type)}\n"
for index, label in enumerate(self._vertex_labels):
props = [
(prop_name, types_pb2.DataType.Name(prop_type))
for prop_name, prop_type in self._vertex_properties[index].items()
]
s += "label: {}\ntype: VERTEX\nproperties: {}\n\n".format(label, props)
props = list(self._vertex_properties[index].keys())
s += f"label: {label}\ntype: VERTEX\nproperties: {props}\n\n"
for index, label in enumerate(self.edge_labels):
props = [
(prop_name, types_pb2.DataType.Name(prop_type))
for prop_name, prop_type in self._edge_properties[index].items()
]
s += """label: {}\ntype: EDGE\nproperties: {}\nrelations: {}\n\n""".format(
label, props, self._edge_relationships[index]
)
props = list(self._edge_properties[index].keys())
s += f"""label: {label}\ntype: EDGE\nproperties: {props}\nrelations: {self._edge_relationships[index]}\n\n"""
return s

def __str__(self):
Expand Down
3 changes: 3 additions & 0 deletions python/graphscope/interactive/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ def __init__(self, graphscope_session, object_id, front_ip, front_port):
self._client = Client(self._graph_url, "g")
self._closed = False

def __repr__(self):
return f"graphscope.InteractiveQuery <{self._graph_url}>"

@property
def object_id(self):
"""Get the vineyard object id of graph.
Expand Down

0 comments on commit 5b5061d

Please sign in to comment.