Skip to content

new: use_experimental_views #41

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions nx_arangodb/classes/digraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def __init__(
read_batch_size: int = 100000,
write_batch_size: int = 50000,
symmetrize_edges: bool = False,
use_experimental_views: bool = False,
*args: Any,
**kwargs: Any,
):
Expand All @@ -48,6 +49,7 @@ def __init__(
read_batch_size,
write_batch_size,
symmetrize_edges,
use_experimental_views,
*args,
**kwargs,
)
Expand Down
9 changes: 5 additions & 4 deletions nx_arangodb/classes/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,19 @@ def __init__(
read_batch_size: int = 100000,
write_batch_size: int = 50000,
symmetrize_edges: bool = False,
use_experimental_views: bool = False,
*args: Any,
**kwargs: Any,
):
self._db = None
self.__name = None
self._graph_exists_in_db = False
self.__use_experimental_views = use_experimental_views

self._set_db(db)
if self._db is not None:
self._set_graph_name(name)

# We need to store the data transfer properties as some functions will need them
self.read_parallelism = read_parallelism
self.read_batch_size = read_batch_size
self.write_batch_size = write_batch_size
Expand Down Expand Up @@ -395,23 +396,23 @@ def clear_nxcg_cache(self):

@cached_property
def nodes(self):
if self.graph_exists_in_db:
if self.__use_experimental_views and self.graph_exists_in_db:
logger.warning("nxadb.CustomNodeView is currently EXPERIMENTAL")
return CustomNodeView(self)

return super().nodes

@cached_property
def adj(self):
if self.graph_exists_in_db:
if self.__use_experimental_views and self.graph_exists_in_db:
logger.warning("nxadb.CustomAdjacencyView is currently EXPERIMENTAL")
return CustomAdjacencyView(self._adj)

return super().adj

@cached_property
def edges(self):
if self.graph_exists_in_db:
if self.__use_experimental_views and self.graph_exists_in_db:
if self.is_directed():
logger.warning("CustomEdgeView for Directed Graphs not yet implemented")
return super().edges
Expand Down
2 changes: 2 additions & 0 deletions nx_arangodb/classes/multidigraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def __init__(
read_batch_size: int = 100000,
write_batch_size: int = 50000,
symmetrize_edges: bool = False,
use_experimental_views: bool = False,
*args: Any,
**kwargs: Any,
):
Expand All @@ -47,6 +48,7 @@ def __init__(
read_batch_size,
write_batch_size,
symmetrize_edges,
use_experimental_views,
*args,
**kwargs,
)
Expand Down
4 changes: 4 additions & 0 deletions nx_arangodb/classes/multigraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ def __init__(
read_parallelism: int = 10,
read_batch_size: int = 100000,
write_batch_size: int = 50000,
symmetrize_edges: bool = False,
use_experimental_views: bool = False,
*args: Any,
**kwargs: Any,
):
Expand All @@ -46,6 +48,8 @@ def __init__(
read_parallelism,
read_batch_size,
write_batch_size,
symmetrize_edges,
use_experimental_views,
*args,
**kwargs,
)
Expand Down
14 changes: 9 additions & 5 deletions tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ def test_node_dict_update_existing_single_collection(
) -> None:
# This tests uses the existing nodes and updates each
# of them using the update method using a single collection
G_1 = nxadb.Graph(name="KarateGraph", foo="bar")
G_1 = nxadb.Graph(name="KarateGraph", foo="bar", use_experimental_views=True)

nodes_ids_list = G_1.nodes
local_nodes_dict = {}
Expand Down Expand Up @@ -379,7 +379,9 @@ def test_node_dict_update_multiple_collections(
assert db.collection(e_1_name).count() == 0
assert db.collection(e_2_name).count() == 0

G_1 = graph_cls(name=graph_name, default_node_type=v_1_name)
G_1 = graph_cls(
name=graph_name, default_node_type=v_1_name, use_experimental_views=True
)
assert len(G_1.nodes) == 0
assert len(G_1.edges) == 0

Expand Down Expand Up @@ -419,7 +421,7 @@ def test_node_dict_update_multiple_collections(
def test_edge_adj_dict_update_existing_single_collection_graph_and_digraph(
load_karate_graph: Any, graph_cls: type[nxadb.Graph]
) -> None:
G_1 = graph_cls(name="KarateGraph", foo="bar")
G_1 = graph_cls(name="KarateGraph", foo="bar", use_experimental_views=True)

local_adj = G_1.adj
local_edges_dict: Union[GraphAdjDict | DiGraphAdjDict] = {}
Expand Down Expand Up @@ -468,7 +470,7 @@ def test_edge_adj_dict_update_existing_single_collection_graph_and_digraph(
def test_edge_adj_dict_update_existing_single_collection_MultiGraph_and_MultiDiGraph(
load_karate_graph: Any, graph_cls: type[nxadb.Graph]
) -> None:
G_1 = graph_cls(name="KarateGraph", foo="bar")
G_1 = graph_cls(name="KarateGraph", foo="bar", use_experimental_views=True)

local_adj = G_1.adj
local_edges_dict: Union[MultiGraphAdjDict | MultiDiGraphAdjDict] = {}
Expand Down Expand Up @@ -523,7 +525,9 @@ def test_edge_dict_update_multiple_collections(load_two_relation_graph: Any) ->
assert db.collection(e_1_name).count() == 0
assert db.collection(e_2_name).count() == 0

G_1 = nxadb.Graph(name=graph_name, default_node_type=v_1_name)
G_1 = nxadb.Graph(
name=graph_name, default_node_type=v_1_name, use_experimental_views=True
)
assert len(G_1.nodes) == 0
assert len(G_1.edges) == 0

Expand Down