@@ -2674,8 +2674,10 @@ class _FuncInfo(object):
2674
2674
is bounded in the interval 0-1 (bounded_0_1), or
2675
2675
a method that returns the information depending
2676
2676
on this
2677
- * A callable (check_params) that returns a bool specifying if a
2678
- certain combination of parameters is valid.
2677
+ * A callable (check_params) that takes a list of the parameters
2678
+ and returns a boolean specifying if a certain combination of
2679
+ parameters is valid. It is only required if the function as
2680
+ parameters and some of them are restricted.
2679
2681
2680
2682
"""
2681
2683
def __init__ (self , function , inverse , bounded_0_1 = True , check_params = None ):
@@ -2692,9 +2694,12 @@ def __init__(self, function, inverse, bounded_0_1=True, check_params=None):
2692
2694
elif callable (check_params ):
2693
2695
self ._check_params = check_params
2694
2696
else :
2695
- raise ValueError ("Check params must be a callable, returning "
2696
- "a boolean with the validity of the passed "
2697
- "parameters, or None." )
2697
+ raise ValueError ("Check params must be a callable taking a list "
2698
+ "with function parameters and returning a "
2699
+ "boolean indicating whether that combination of "
2700
+ "parameters is valid. In case of validity for "
2701
+ "any combination of parameters it may be set "
2702
+ "to None." )
2698
2703
2699
2704
def is_bounded_0_1 (self , params = None ):
2700
2705
return self ._bounded_0_1 (params )
@@ -2769,7 +2774,7 @@ def __init__(self, str_func):
2769
2774
"""
2770
2775
2771
2776
if not isinstance (str_func , six .string_types ):
2772
- raise ValueError ("The argument passed is not a string." )
2777
+ raise ValueError ("'%s' is not a string." % str_func )
2773
2778
self ._str_func = six .text_type (str_func )
2774
2779
self ._key , self ._params = self ._get_key_params ()
2775
2780
self ._func = self ._parse_func ()
@@ -2783,7 +2788,11 @@ def _parse_func(self):
2783
2788
"""
2784
2789
2785
2790
func = self ._funcs [self ._key ]
2786
- if self ._params :
2791
+
2792
+ if not self ._params :
2793
+ func = _FuncInfo (func .function , func .inverse ,
2794
+ func .is_bounded_0_1 ())
2795
+ else :
2787
2796
m = func .function
2788
2797
function = (lambda x , m = m : m (x , self ._params ))
2789
2798
@@ -2794,9 +2803,6 @@ def _parse_func(self):
2794
2803
2795
2804
func = _FuncInfo (function , inverse ,
2796
2805
is_bounded_0_1 )
2797
- else :
2798
- func = _FuncInfo (func .function , func .inverse ,
2799
- func .is_bounded_0_1 ())
2800
2806
return func
2801
2807
2802
2808
@property
@@ -2838,27 +2844,26 @@ def _get_key_params(self):
2838
2844
regex = '\{(.*?)\}'
2839
2845
params = re .findall (regex , str_func )
2840
2846
2841
- if params :
2842
- for i , param in enumerate (params ):
2843
- try :
2844
- params [i ] = float (param )
2845
- except ValueError :
2846
- raise ValueError ("Parameter %i is '%s', which is "
2847
- "not a number." %
2848
- (i , param ))
2847
+ for i , param in enumerate (params ):
2848
+ try :
2849
+ params [i ] = float (param )
2850
+ except ValueError :
2851
+ raise ValueError ("Parameter %i is '%s', which is "
2852
+ "not a number." %
2853
+ (i , param ))
2849
2854
2850
- str_func = re .sub (regex , '{p}' , str_func )
2855
+ str_func = re .sub (regex , '{p}' , str_func )
2851
2856
2852
2857
try :
2853
2858
func = self ._funcs [str_func ]
2854
2859
except (ValueError , KeyError ):
2855
- raise ValueError ("%s: invalid string. The only strings "
2860
+ raise ValueError ("'%s' is an invalid string. The only strings "
2856
2861
"recognized as functions are %s." %
2857
2862
(str_func , list (self ._funcs )))
2858
2863
2859
2864
# Checking that the parameters are valid
2860
2865
if not func .check_params (params ):
2861
-
4B6E
raise ValueError ("%s: are invalid values for the parameters "
2866
+ raise ValueError ("%s are invalid values for the parameters "
2862
2867
"in %s." %
2863
2868
(params , str_func ))
2864
2869
0 commit comments