22 __all__ = [
"RangeField"]
24 from .config
import Field, _typeStr
25 from .callStack
import getStackFrame
29 """A configuration field (`lsst.pex.config.Field` subclass) that requires 30 the value to be in a specific numeric range. 35 A description of the field. 36 dtype : {`int`-type, `float`-type} 37 The field's data type: either the `int` or `float` type. 38 default : `int` or `float`, optional 39 Default value for the field. 40 optional : `bool`, optional 41 When `False`, `lsst.pex.config.Config.validate` will fail if the 42 field's value is `None`. 43 min : int, float, or `None`, optional 44 Minimum value accepted in the range. If `None`, the range has no 45 lower bound (equivalent to negative infinity). 46 max : `int`, `float`, or None, optional 47 Maximum value accepted in the range. If `None`, the range has no 48 upper bound (equivalent to positive infinity). 49 inclusiveMin : `bool`, optional 50 If `True` (default), the ``min`` value is included in the allowed 52 inclusiveMax : `bool`, optional 53 If `True` (default), the ``max`` value is included in the allowed 55 deprecated : None or `str`, optional 56 A description of why this Field is deprecated, including removal date. 57 If not None, the string is appended to the docstring for this Field. 72 supportedTypes = set((int, float))
73 """The set of data types allowed by `RangeField` instances (`set` 74 containing `int` and `float` types). 77 def __init__(self, doc, dtype, default=None, optional=False,
78 min=None, max=None, inclusiveMin=True, inclusiveMax=False,
81 raise ValueError(
"Unsupported RangeField dtype %s" % (_typeStr(dtype)))
83 if min
is None and max
is None:
84 raise ValueError(
"min and max cannot both be None")
86 if min
is not None and max
is not None:
88 raise ValueError(
"min = %s > %s = max" % (min, max))
89 elif min == max
and not (inclusiveMin
and inclusiveMax):
90 raise ValueError(
"min = max = %s and min and max not both inclusive" % (min,))
93 """Minimum value accepted in the range. If `None`, the range has no 94 lower bound (equivalent to negative infinity). 98 """Maximum value accepted in the range. If `None`, the range has no 99 upper bound (equivalent to positive infinity). 103 self.
maxCheck =
lambda x, y:
True if y
is None else x <= y
105 self.
maxCheck =
lambda x, y:
True if y
is None else x < y
107 self.
minCheck =
lambda x, y:
True if y
is None else x >= y
109 self.
minCheck =
lambda x, y:
True if y
is None else x > y
110 self.
_setup(doc, dtype=dtype, default=default, check=
None, optional=optional, source=source,
111 deprecated=deprecated)
113 ((
"[" if inclusiveMin
else "("),
114 (
"-inf" if self.
min is None else self.
min),
115 (
"inf" if self.
max is None else self.
max),
116 (
"]" if inclusiveMax
else ")"))
117 """String representation of the field's allowed range (`str`). 122 def _validateValue(self, value):
123 Field._validateValue(self, value)
126 msg =
"%s is outside of valid range %s" % (value, self.
rangeString)
127 raise ValueError(msg)
def __init__(self, doc, dtype, default=None, optional=False, min=None, max=None, inclusiveMin=True, inclusiveMax=False, deprecated=None)
def getStackFrame(relative=0)
def _setup(self, doc, dtype, default, check, optional, source, deprecated)