LSSTApplications  10.0+286,10.0+36,10.0+46,10.0-2-g4f67435,10.1+152,10.1+37,11.0,11.0+1,11.0-1-g47edd16,11.0-1-g60db491,11.0-1-g7418c06,11.0-2-g04d2804,11.0-2-g68503cd,11.0-2-g818369d,11.0-2-gb8b8ce7
LSSTDataManagementBasePackage
Public Member Functions | Public Attributes | Private Member Functions | List of all members
lsst.pex.config.listField.ListField Class Reference
Inheritance diagram for lsst.pex.config.listField.ListField:

Public Member Functions

def __init__
 
def validate
 
def __set__
 
def toDict
 

Public Attributes

 listCheck
 
 itemCheck
 
 itemtype
 
 length
 
 minLength
 
 maxLength
 

Private Member Functions

def _compare
 

Detailed Description

Defines a field which is a container of values of type dtype

If length is not None, then instances of this field must match this length 
exactly.
If minLength is not None, then instances of the field must be no shorter 
then minLength
If maxLength is not None, then instances of the field must be no longer 
than maxLength

Additionally users can provide two check functions:
listCheck - used to validate the list as a whole, and
itemCheck - used to validate each item individually    

Definition at line 141 of file listField.py.

Constructor & Destructor Documentation

def lsst.pex.config.listField.ListField.__init__ (   self,
  doc,
  dtype,
  default = None,
  optional = False,
  listCheck = None,
  itemCheck = None,
  length = None,
  minLength = None,
  maxLength = None 
)

Definition at line 158 of file listField.py.

159  length=None, minLength=None, maxLength=None):
160  if dtype not in Field.supportedTypes:
161  raise ValueError("Unsupported dtype %s"%_typeStr(dtype))
162  if length is not None:
163  if length <= 0:
164  raise ValueError("'length' (%d) must be positive"%length)
165  minLength=None
166  maxLength=None
167  else:
168  if maxLength is not None and maxLength <= 0:
169  raise ValueError("'maxLength' (%d) must be positive"%maxLength)
170  if minLength is not None and maxLength is not None \
171  and minLength > maxLength:
172  raise ValueError("'maxLength' (%d) must be at least as large as 'minLength' (%d)"%(maxLength, minLength))
173 
174  if listCheck is not None and not hasattr(listCheck, "__call__"):
175  raise ValueError("'listCheck' must be callable")
176  if itemCheck is not None and not hasattr(itemCheck, "__call__"):
177  raise ValueError("'itemCheck' must be callable")
178 
179  source = traceback.extract_stack(limit=2)[0]
180  self._setup( doc=doc, dtype=List, default=default, check=None, optional=optional, source=source)
181  self.listCheck = listCheck
182  self.itemCheck = itemCheck
183  self.itemtype = dtype
184  self.length=length
185  self.minLength=minLength
186  self.maxLength=maxLength
187 

Member Function Documentation

def lsst.pex.config.listField.ListField.__set__ (   self,
  instance,
  value,
  at = None,
  label = "assignment" 
)

Definition at line 212 of file listField.py.

213  def __set__(self, instance, value, at=None, label="assignment"):
214  if instance._frozen:
215  raise FieldValidationError(self, instance, "Cannot modify a frozen Config")
216 
217  if at is None:
218  at = traceback.extract_stack()[:-1]
219 
220  if value is not None:
221  value = List(instance, self, value, at, label)
222  else:
223  history = instance._history.setdefault(self.name, [])
224  history.append((value, at, label))
225 
226  instance._storage[self.name] = value
227 
def lsst.pex.config.listField.ListField._compare (   self,
  instance1,
  instance2,
  shortcut,
  rtol,
  atol,
  output 
)
private
Helper function for Config.compare; used to compare two fields for equality.

@param[in] instance1  LHS Config instance to compare.
@param[in] instance2  RHS Config instance to compare.
@param[in] shortcut   If True, return as soon as an inequality is found.
@param[in] rtol       Relative tolerance for floating point comparisons.
@param[in] atol       Absolute tolerance for floating point comparisons.
@param[in] output     If not None, a callable that takes a string, used (possibly repeatedly)
              to report inequalities.

Floating point comparisons are performed by numpy.allclose; refer to that for details.

Definition at line 232 of file listField.py.

233  def _compare(self, instance1, instance2, shortcut, rtol, atol, output):
234  """Helper function for Config.compare; used to compare two fields for equality.
235 
236  @param[in] instance1 LHS Config instance to compare.
237  @param[in] instance2 RHS Config instance to compare.
238  @param[in] shortcut If True, return as soon as an inequality is found.
239  @param[in] rtol Relative tolerance for floating point comparisons.
240  @param[in] atol Absolute tolerance for floating point comparisons.
241  @param[in] output If not None, a callable that takes a string, used (possibly repeatedly)
242  to report inequalities.
243 
244  Floating point comparisons are performed by numpy.allclose; refer to that for details.
245  """
246  l1 = getattr(instance1, self.name)
247  l2 = getattr(instance2, self.name)
248  name = getComparisonName(
249  _joinNamePath(instance1._name, self.name),
250  _joinNamePath(instance2._name, self.name)
251  )
252  if not compareScalars("isnone for %s" % name, l1 is None, l2 is None, output=output):
253  return False
254  if l1 is None and l2 is None:
255  return True
256  if not compareScalars("size for %s" % name, len(l1), len(l2), output=output):
257  return False
258  equal = True
259  for n, v1, v2 in zip(range(len(l1)), l1, l2):
260  result = compareScalars("%s[%d]" % (name, n), v1, v2, dtype=self.dtype,
261  rtol=rtol, atol=atol, output=output)
262  if not result and shortcut:
263  return False
264  equal = equal and result
265  return equal
def lsst.pex.config.listField.ListField.toDict (   self,
  instance 
)

Definition at line 228 of file listField.py.

229  def toDict(self, instance):
230  value = self.__get__(instance)
231  return list(value) if value is not None else None
def lsst.pex.config.listField.ListField.validate (   self,
  instance 
)
ListField validation ensures that non-optional fields are not None,
    and that non-None values comply with length requirements and
    that the list passes listCheck if supplied by the user.
Individual Item checks are applied at set time and are not re-checked.

Definition at line 188 of file listField.py.

189  def validate(self, instance):
190  """
191  ListField validation ensures that non-optional fields are not None,
192  and that non-None values comply with length requirements and
193  that the list passes listCheck if supplied by the user.
194  Individual Item checks are applied at set time and are not re-checked.
195  """
196  Field.validate(self, instance)
197  value = self.__get__(instance)
198  if value is not None:
199  lenValue =len(value)
200  if self.length is not None and not lenValue == self.length:
201  msg = "Required list length=%d, got length=%d"%(self.length, lenValue)
202  raise FieldValidationError(self, instance, msg)
203  elif self.minLength is not None and lenValue < self.minLength:
204  msg = "Minimum allowed list length=%d, got length=%d"%(self.minLength, lenValue)
205  raise FieldValidationError(self, instance, msg)
206  elif self.maxLength is not None and lenValue > self.maxLength:
207  msg = "Maximum allowed list length=%d, got length=%d"%(self.maxLength, lenValue)
208  raise FieldValidationError(self, instance, msg)
209  elif self.listCheck is not None and not self.listCheck(value):
210  msg = "%s is not a valid value"%str(value)
211  raise FieldValidationError(self, instance, msg)

Member Data Documentation

lsst.pex.config.listField.ListField.itemCheck

Definition at line 181 of file listField.py.

lsst.pex.config.listField.ListField.itemtype

Definition at line 182 of file listField.py.

lsst.pex.config.listField.ListField.length

Definition at line 183 of file listField.py.

lsst.pex.config.listField.ListField.listCheck

Definition at line 180 of file listField.py.

lsst.pex.config.listField.ListField.maxLength

Definition at line 185 of file listField.py.

lsst.pex.config.listField.ListField.minLength

Definition at line 184 of file listField.py.


The documentation for this class was generated from the following file: