def assert_valid_percent(x, eq_lower=False, eq_upper=False):
# these are all castable to float
assert_is_type(x, (float, np.float, np.int, int, long, np.long))
x = float(x)
# test lower bound:
if not ((eq_lower and 0. <= x) or ((not eq_lower) and 0. < x)):
raise ValueError('Expected 0. %s x, but got x=%r'
% ('<=' if eq_lower else '<', x))
if not ((eq_upper and x <= 1.) or ((not eq_upper) and x < 1.)):
raise ValueError('Expected x %s 1., but got x=%r'
% ('<=' if eq_upper else '<', x))
return x
评论列表
文章目录