standardize_component_data

(function from pyomo.contrib.pyros.util)

pyomo.contrib.pyros.util.standardize_component_data(obj, valid_ctype, valid_cdatatype, ctype_validator=None, cdatatype_validator=None, allow_repeats=False, from_iterable=None)[source]

Cast an object to a list of Pyomo ComponentData objects.

Parameters:
  • obj (Component, ComponentData, or iterable) – Object from which component data objects are cast.

  • valid_ctype (type or tuple of type) – Valid Component type(s).

  • valid_cdatatype (type or tuple of type) – Valid ComponentData type(s).

  • ctype_validator (None or callable, optional) – Validator for component objects derived from obj.

  • cdatatype_validator (None or callable, optional) – Validator for component data objects derived from obj.

  • allow_repeats (bool, optional) – True to allow for nonunique component data objects derived from obj, False otherwise.

  • from_iterable (str, optional) – Description of the object to include in error messages. Meant to be used if the object is an iterable from which to derive component data objects.

Returns:

The ComponentData objects derived from obj. Note: If obj is a valid ComponentData type, then [obj] is returned.

Return type:

list of ComponentData

Raises:
  • TypeError – If obj is not an iterable and not an instance of valid_ctype or valid_cdatatype.

  • ValueError – If allow_repeats=False and there are duplicates among the component data objects derived from obj.