8000 Feedback from @story645 · matplotlib/matplotlib@94a1af0 · GitHub
[go: up one dir, main page]

Skip to content

Commit 94a1af0

Browse files
committed
Feedback from @story645
1 parent 69f2a04 commit 94a1af0

File tree

1 file changed

+26
-21
lines changed

1 file changed

+26
-21
lines changed

lib/matplotlib/cbook.py

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2674,8 +2674,10 @@ class _FuncInfo(object):
26742674
is bounded in the interval 0-1 (bounded_0_1), or
26752675
a method that returns the information depending
26762676
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.
26792681
26802682
"""
26812683
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):
26922694
elif callable(check_params):
26932695
self._check_params = check_params
26942696
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.")
26982703

26992704
def is_bounded_0_1(self, params=None):
27002705
return self._bounded_0_1(params)
@@ -2769,7 +2774,7 @@ def __init__(self, str_func):
27692774
"""
27702775

27712776
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)
27732778
self._str_func = six.text_type(str_func)
27742779
self._key, self._params = self._get_key_params()
27752780
self._func = self._parse_func()
@@ -2783,7 +2788,11 @@ def _parse_func(self):
27832788
"""
27842789

27852790
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:
27872796
m = func.function
27882797
function = (lambda x, m=m: m(x, self._params))
27892798

@@ -2794,9 +2803,6 @@ def _parse_func(self):
27942803

27952804
func = _FuncInfo(function, inverse,
27962805
is_bounded_0_1)
2797-
else:
2798-
func = _FuncInfo(func.function, func.inverse,
2799-
func.is_bounded_0_1())
28002806
return func
28012807

28022808
@property
@@ -2838,27 +2844,26 @@ def _get_key_params(self):
28382844
regex = '\{(.*?)\}'
28392845
params = re.findall(regex, str_func)
28402846

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))
28492854

2850-
str_func = re.sub(regex, '{p}', str_func)
2855+
str_func = re.sub(regex, '{p}', str_func)
28512856

28522857
try:
28532858
func = self._funcs[str_func]
28542859
except (ValueError, KeyError):
2855-
raise ValueError("%s: invalid string. The only strings "
2860+
raise ValueError("'%s' is an invalid string. The only strings "
28562861
"recognized as functions are %s." %
28572862
(str_func, list(self._funcs)))
28582863

28592864
# Checking that the parameters are valid
28602865
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 "
28622867
"in %s." %
28632868
(params, str_func))
28642869

0 commit comments

Comments
 (0)
0