Skip to content
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

Raise informative ValueError's #61

Merged
merged 1 commit into from
Sep 19, 2024
Merged
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
20 changes: 14 additions & 6 deletions movement_primitives/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,23 +103,31 @@ def configure(
"""
if t is not None:
self.t = t

def check_length(var, var_name, expected):
"""Raise ValueError if 'var' does not have length 'expected', using 'var_name' in the message."""
nv = len(var)
if nv != expected:
s = "s" if expected > 1 else ""
raise ValueError(f"expected {var_name} with {expected} element{s}, got {nv}")

if start_y is not None:
assert len(start_y) == self.n_dims, f"{len(start_y)}"
check_length(start_y, "start_y", self.n_dims)
self.start_y = start_y
if start_yd is not None:
assert len(start_yd) == self.n_vel_dims, f"{len(start_yd)}"
check_length(start_yd, "start_yd", self.n_vel_dims)
self.start_yd = start_yd
if start_ydd is not None:
assert len(start_ydd) == self.n_vel_dims, f"{len(start_ydd)}"
check_length(start_ydd, "start_ydd", self.n_vel_dims)
self.start_ydd = start_ydd
if goal_y is not None:
assert len(goal_y) == self.n_dims, f"{len(goal_y)}"
check_length(goal_y, "goal_y", self.n_dims)
self.goal_y = goal_y
if goal_yd is not None:
assert len(goal_yd) == self.n_vel_dims, f"{len(goal_yd)}"
check_length(goal_yd, "goal_yd", self.n_vel_dims)
self.goal_yd = goal_yd
if goal_ydd is not None:
assert len(goal_ydd) == self.n_vel_dims, f"{len(goal_ydd)}"
check_length(goal_ydd, "goal_ydd", self.n_vel_dims)
self.goal_ydd = goal_ydd

@abc.abstractmethod
Expand Down