From b9fbb541168afd1fa16e3ad0fe6d053fb447e5e5 Mon Sep 17 00:00:00 2001 From: abeerfatima <63760665+abeerfatima@users.noreply.github.com> Date: Sat, 11 Jun 2022 12:24:51 -0400 Subject: [PATCH] Add assert statements to catch undefined components in system function calls #95 --- payload_designer/luts/functions.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/payload_designer/luts/functions.py b/payload_designer/luts/functions.py index 235e177..f9fb1a5 100644 --- a/payload_designer/luts/functions.py +++ b/payload_designer/luts/functions.py @@ -35,6 +35,9 @@ def __init__(self, path: Path, name: str = None): self.name = name def get_table(self): + assert self.x is not None, "x must be specified." + assert self.y is not None, "y must be specified." + data = {f"X [{self.x.unit}]": self.x.value, f"Y [{self.y.unit}]": self.y.value} df = pd.DataFrame.from_dict(data) @@ -42,10 +45,12 @@ def get_table(self): return df def __str__(self): + assert self.name is not None, "Name must be specified." df = self.get_table() return f"LUT ({self.name})\n{df.to_string(index=False)}" def _repr_html_(self): + assert self.name is not None, "Name must be specified." df = self.get_table() return f"LUT ({self.name})\n{df.to_html(index=False)}" @@ -59,6 +64,8 @@ def __call__(self, x): array-like: The interpolated y values. """ + assert self.x is not None, "x must be specified." + assert self.y is not None, "y must be specified." return np.interp(x=x, xp=self.x, fp=self.y)