Skip to content

Commit

Permalink
raise NotImplemented errors
Browse files Browse the repository at this point in the history
  • Loading branch information
pattonw committed May 11, 2023
1 parent c88ac48 commit 96bd8a7
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 22 deletions.
24 changes: 13 additions & 11 deletions funlib/persistence/graphs/file_graph_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,18 +416,19 @@ def write_edges(
fail_if_not_exists=False,
delete=False,
):
assert not delete, "Delete not implemented"
assert not (
fail_if_exists and fail_if_not_exists
), "Cannot have fail_if_exists and fail_if_not_exists simultaneously"
if delete:
raise NotImplementedError("Delete not implemented for file backend")
if fail_if_exists:
raise RuntimeError("Fail if exists not implemented for " "file backend")
raise NotImplementedError("Fail if exists not implemented for file backend")
if fail_if_not_exists:
raise RuntimeError("Fail if not exists not implemented for " "file backend")
raise NotImplementedError("Fail if not exists not implemented for file backend")
if attributes is not None:
raise RuntimeError("Attributes not implemented for file backend")
raise NotImplementedError("Attributes not implemented for file backend")
if self.graph_provider.mode == "r":
raise RuntimeError("Trying to write to read-only DB")
raise NotImplementedError("Trying to write to read-only DB")
if roi is None:
roi = self.roi

Expand Down Expand Up @@ -470,18 +471,19 @@ def write_nodes(
fail_if_not_exists=False,
delete=False,
):
assert not delete, "Delete not implemented"
assert not (
fail_if_exists and fail_if_not_exists
), "Cannot have fail_if_exists and fail_if_not_exists simultaneously"
if delete:
raise NotImplementedError("Delete not implemented for file backend")
if fail_if_exists:
raise RuntimeError("Fail if exists not implemented for " "file backend")
raise NotImplementedError("Fail if exists not implemented for " "file backend")
if fail_if_not_exists:
raise RuntimeError("Fail if not exists not implemented for " "file backend")
raise NotImplementedError("Fail if not exists not implemented for " "file backend")
if attributes is not None:
raise RuntimeError("Attributes not implemented for file backend")
raise NotImplementedError("Attributes not implemented for file backend")
if self.graph_provider.mode == "r":
raise RuntimeError("Trying to write to read-only DB")
raise NotImplementedError("Trying to write to read-only DB")

if roi is None:
roi = self.roi
Expand Down Expand Up @@ -528,7 +530,7 @@ def __contains(self, roi, node):
return roi.contains(Coordinate(node_data["position"]))

def is_directed(self):
raise RuntimeError("not implemented in %s" % self.name())
raise NotImplementedError("not implemented in %s" % self.name())


class FileSubGraph(FileSharedSubGraph, Graph):
Expand Down
16 changes: 9 additions & 7 deletions funlib/persistence/graphs/mongodb_graph_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,9 +489,7 @@ def __disconnect(self):
self.edges = None
self.meta = None
self.database = None
if self.client:
self.client.close()
self.client = None
self.client = None

def __create_node_collection(self):
"""Creates the node collection, including indexes"""
Expand Down Expand Up @@ -633,7 +631,8 @@ def write_nodes(
fail_if_not_exists=False,
delete=False,
):
assert not delete, "Delete not implemented"
if delete:
raise NotImplementedError("Delete not implemented for file backend")
assert not (
fail_if_exists and fail_if_not_exists
), "Cannot have fail_if_exists and fail_if_not_exists simultaneously"
Expand Down Expand Up @@ -691,7 +690,8 @@ def write_edges(
fail_if_not_exists=False,
delete=False,
):
assert not delete, "Delete not implemented"
if delete:
raise NotImplementedError("Delete not implemented for file backend")
assert not (
fail_if_exists and fail_if_not_exists
), "Cannot have fail_if_exists and fail_if_not_exists simultaneously"
Expand All @@ -710,6 +710,7 @@ def write_edges(
for u, v, data in self.edges(data=True):
if not self.is_directed():
u, v = min(u, v), max(u, v)

if not self.__contains(roi, u):
logger.debug(
(
Expand Down Expand Up @@ -904,7 +905,8 @@ def __write(
see write_nodes or write_edges for explanations of these flags
"""
assert not delete, "Delete not implemented"
if delete:
raise NotImplementedError("Delete not implemented for file backend")
match_docs = []
for doc in docs:
match_doc = {}
Expand Down Expand Up @@ -977,7 +979,7 @@ def __contains(self, roi, node):
return roi.contains(Coordinate(coordinate))

def is_directed(self):
raise RuntimeError("not implemented in %s" % self.name())
raise NotImplementedError("not implemented in %s" % self.name())


class MongoDbSubGraph(MongoDbSharedSubGraph, Graph):
Expand Down
8 changes: 4 additions & 4 deletions funlib/persistence/graphs/shared_graph_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class SharedGraphProvider(object):
"""

def __getitem__(self, roi):
raise RuntimeError("not implemented in %s" % self.name())
raise NotImplementedError("not implemented in %s" % self.name())

def name(self):
return type(self).__name__
Expand Down Expand Up @@ -61,7 +61,7 @@ def write_edges(
in subgraph.
"""
raise RuntimeError("not implemented in %s" % self.name())
raise NotImplementedError("not implemented in %s" % self.name())

def write_nodes(
self,
Expand Down Expand Up @@ -93,13 +93,13 @@ def write_nodes(
in subgraph.
"""
raise RuntimeError("not implemented in %s" % self.name())
raise NotImplementedError("not implemented in %s" % self.name())

def get_connected_components(self):
"""Returns a list of connected components from the nodes and edges
in the subgraph. For directed graphs, weak connectivity is sufficient.
"""
raise RuntimeError("not implemented in %s" % self.name())
raise NotImplementedError("not implemented in %s" % self.name())

def name(self):
return type(self).__name__
Expand Down

0 comments on commit 96bd8a7

Please sign in to comment.