Skip to content

Commit

Permalink
Use None to select all property, and empty list to deselect all. (#224)
Browse files Browse the repository at this point in the history
  • Loading branch information
siyuan0322 authored Apr 2, 2021
1 parent af4f6e6 commit 219ca56
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
4 changes: 2 additions & 2 deletions python/graphscope/framework/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,7 @@ def _construct_graph(
graph._base_graph = self._base_graph or self
return graph

def add_vertices(self, vertices, label="_", properties=[], vid_field=0):
def add_vertices(self, vertices, label="_", properties=None, vid_field=0):
is_from_existed_graph = len(self._unsealed_vertices) != len(
self._v_labels
) or len(self._unsealed_edges) != len(self._e_labels)
Expand Down Expand Up @@ -758,7 +758,7 @@ def add_edges(
self,
edges,
label="_",
properties=[],
properties=None,
src_label=None,
dst_label=None,
src_field=0,
Expand Down
4 changes: 2 additions & 2 deletions python/graphscope/framework/graph_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def finish(self, id_type: str = "int64_t"):
elif self.loader.deduced_properties:
self.add_properties(self.loader.deduced_properties)
self.loader.select_columns(
self.properties, include_all=bool(not self.raw_properties)
self.properties, include_all=bool(self.raw_properties is None)
)
self.loader.finish()
self._finished = True
Expand Down Expand Up @@ -163,7 +163,7 @@ def finish(self, id_type: str = "int64_t"):
elif self.loader.deduced_properties:
self.add_properties(self.loader.deduced_properties)
self.loader.select_columns(
self.properties, include_all=bool(not self.raw_properties)
self.properties, include_all=bool(self.raw_properties is None)
)
self.loader.finish()
self._finished = True
Expand Down
3 changes: 3 additions & 0 deletions python/graphscope/framework/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#

import logging
import pathlib
from typing import Dict
from typing import Sequence
from typing import Tuple
Expand Down Expand Up @@ -170,6 +171,8 @@ def resolve(self, source):
"""
if isinstance(source, str):
self.process_location(source)
elif isinstance(source, pathlib.Path):
self.process_location(str(source))
elif isinstance(source, pd.DataFrame):
self.process_pandas(source)
elif vineyard is not None and isinstance(
Expand Down
18 changes: 13 additions & 5 deletions python/tests/test_create_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,20 +205,28 @@ def test_complete_form_loader_deprecated(
assert graph.loaded()


def test_properties_omitted_loader(graphscope_session, student_group_e, student_v):
def test_default_prop_is_none_loader(graphscope_session, student_group_e, student_v):
graph = graphscope_session.g(generate_eid=False)
graph = graph.add_vertices(student_v, "student", [], "student_id")
graph = graph.add_edges(student_group_e, "group", [])
graph = graph.add_vertices(student_v, "student")
graph = graph.add_edges(student_group_e, "group")
assert len(graph.schema.get_vertex_properties("student")) == 4
assert len(graph.schema.get_edge_properties("group")) == 2


def test_prop_is_empty_loader(graphscope_session, student_group_e, student_v):
graph = graphscope_session.g(generate_eid=False)
graph = graph.add_vertices(student_v, "student", [], "student_id")
graph = graph.add_edges(student_group_e, "group", [])
assert len(graph.schema.get_vertex_properties("student")) == 1
assert len(graph.schema.get_edge_properties("group")) == 0


def test_properties_omitted_loader_with_generate_eid(
graphscope_session, student_group_e, student_v
):
graph = graphscope_session.g(generate_eid=True)
graph = graph.add_vertices(student_v, "student", [], "student_id")
graph = graph.add_edges(student_group_e, "group", [])
graph = graph.add_vertices(student_v, "student", None, "student_id")
graph = graph.add_edges(student_group_e, "group", None)
assert len(graph.schema.get_vertex_properties("student")) == 4
assert len(graph.schema.get_edge_properties("group")) == 3

Expand Down

0 comments on commit 219ca56

Please sign in to comment.