From 85ca26176b276e4d693179c14796732dfa9c6e77 Mon Sep 17 00:00:00 2001 From: nstarman Date: Wed, 30 Aug 2023 12:45:35 -0400 Subject: [PATCH] replace assert with ValueError Signed-off-by: nstarman --- src/daft/_core.py | 9 ++++----- src/daft/_utils.py | 29 +++++++++++++++++------------ 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/src/daft/_core.py b/src/daft/_core.py index f99dce8..99dab3c 100644 --- a/src/daft/_core.py +++ b/src/daft/_core.py @@ -580,13 +580,12 @@ 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( + 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 diff --git a/src/daft/_utils.py b/src/daft/_utils.py index 18f4c28..7d41243 100644 --- a/src/daft/_utils.py +++ b/src/daft/_utils.py @@ -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 @@ -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) @@ -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: