Skip to content

Commit

Permalink
replace assert with ValueError (#171)
Browse files Browse the repository at this point in the history
Signed-off-by: nstarman <nstarman@users.noreply.github.com>
  • Loading branch information
nstarman committed Sep 18, 2023
1 parent 7e859f2 commit 2a8604a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 18 deletions.
12 changes: 6 additions & 6 deletions src/daft/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -580,13 +580,13 @@ def __init__(
# Iterable is consumed, so first condition checks if two or more are
# true
node_style = iter((observed, alternate, fixed))
test = (any(node_style) and not any(node_style)) or not any(
(observed, alternate, fixed)
)
if not (
(any(node_style) and not any(node_style))
or not any((observed, alternate, fixed))
):
msg = "A node cannot be more than one of `observed`, `fixed`, or `alternate`."
raise ValueError(msg)

assert (
test
), "A node cannot be more than one of `observed`, `fixed`, or `alternate`."
self.observed = observed
self.fixed = fixed
self.alternate = alternate
Expand Down
29 changes: 17 additions & 12 deletions src/daft/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,20 @@ def __init__(self, **kwargs):

# Make sure that the observed node style is one that we recognize.
self.observed_style = kwargs.get("observed_style", "shaded").lower()
styles = ["shaded", "inner", "outer"]
assert self.observed_style in styles, (
f"Unrecognized observed node style: {self.observed_style}\n"
+ "\tOptions are: {}".format(", ".join(styles))
)
styles = ("shaded", "inner", "outer")
if self.observed_style not in styles:
raise ValueError(
f"Unrecognized observed node style: {self.observed_style}\n"
f"\tOptions are: {', '.join(styles)}"
)

# Make sure that the alternate node style is one that we recognize.
self.alternate_style = kwargs.get("alternate_style", "inner").lower()
styles = ["shaded", "inner", "outer"]
assert self.alternate_style in styles, (
f"Unrecognized alternate node style: {self.alternate_style}\n"
+ "\tOptions are: {}".format(", ".join(styles))
)
if self.alternate_style not in styles:
raise ValueError(
f"Unrecognized observed node style: {self.alternate_style}\n"
f"\tOptions are: {', '.join(styles)}"
)

# Set up the figure and grid dimensions.
self.padding = 0.1
Expand Down Expand Up @@ -159,7 +160,10 @@ def convert(self, *xy):
Convert from model coordinates to plot coordinates.
"""
assert len(xy) == 2
if len(xy) != 2:
raise ValueError(
"You must provide two coordinates to `convert()`."
)
return self.grid_unit * (np.atleast_1d(xy) - self.origin)


Expand All @@ -183,7 +187,8 @@ def _pop_multiple(_dict, default, *args):
The arguments to try to retrieve.
"""
assert len(args) > 0, "You must provide at least one argument to `pop()`."
if len(args) == 0:
raise ValueError("You must provide at least one argument to `pop()`.")

results = []
for arg in args:
Expand Down

0 comments on commit 2a8604a

Please sign in to comment.