NamedValueSet¶
-
class
lsst.daf.butler.NamedValueSet(elements: Iterable[K] = ())¶ Bases:
lsst.daf.butler.NameMappingSetView,lsst.daf.butler.NamedValueMutableSetA custom mutable set class that requires elements to have a
.nameattribute, which can then be used as keys indict-like lookup.Names and elements can both be used with the
inanddeloperators,remove, anddiscard. Names (but not elements) can be used with[]-based element retrieval (not assignment) and thegetmethod.Parameters: - elements :
iterable Iterable over elements to include in the set.
Raises: - AttributeError
Raised if one or more elements do not have a
.nameattribute.
Notes
Iteration order is guaranteed to be the same as insertion order (with the same general behavior as
dictordering). Likedicts, sets with the same elements will compare as equal even if their iterator order is not the same.Attributes Summary
namesThe set of names associated with the keys, in the same order ( AbstractSet[str]).Methods Summary
add(element)Add an element to the set. asMapping()Return a mapping view with names as keys. clear()This is slow (creates N new iterators!) but effective. copy()Return a new NamedValueSetwith the same elements.discard(element, K])Remove an element from the set if it exists. freeze()Disable all mutators, effectively transforming selfinto an immutable set.get(key, K_co], default)Return the element with the given name, or defaultif no such element is present.isdisjoint(other)Return True if two sets have a null intersection. issubset(other)issuperset(other)pop(*args)Remove and return an element from the set. remove(element, K])Remove an element from the set. update(elements)Add multiple new elements to the set. Attributes Documentation
Methods Documentation
-
add(element: K) → None¶ Add an element to the set.
Raises: - AttributeError
Raised if the element does not have a
.nameattribute.
-
asMapping() → Mapping[str, K_co]¶ Return a mapping view with names as keys.
Returns: - dict :
Mapping A dictionary-like view with
values() == self.
- dict :
-
clear() → None¶ This is slow (creates N new iterators!) but effective.
-
copy() → lsst.daf.butler.core.named.NamedValueSet[~K][K]¶ Return a new
NamedValueSetwith the same elements.
-
discard(element: Union[str, K]) → Any¶ Remove an element from the set if it exists.
Does nothing if no matching element is present.
Parameters:
-
freeze() → lsst.daf.butler.core.named.NamedValueAbstractSet[~K][K]¶ Disable all mutators, effectively transforming
selfinto an immutable set.Returns: - self :
NamedValueAbstractSet While
selfis modified in-place, it is also returned with a type anotation that reflects its new, frozen state; assigning it to a new variable (and considering any previous references invalidated) should allow for more accurate static type checking.
- self :
-
get(key: Union[str, K_co], default: Optional[Any] = None) → Any¶ Return the element with the given name, or
defaultif no such element is present.
-
isdisjoint(other)¶ Return True if two sets have a null intersection.
-
issubset(other: AbstractSet[K]) → bool¶
-
issuperset(other: AbstractSet[K]) → bool¶
-
pop(*args) → K¶ Remove and return an element from the set.
Parameters: - name :
str, optional Name of the element to remove and return. Must be passed positionally. If not provided, an arbitrary element is removed and returned.
Raises: - KeyError
Raised if
nameis provided butdefaultis not, and no matching element exists.
- name :
-
remove(element: Union[str, K]) → Any¶ Remove an element from the set.
Parameters: Raises: - KeyError
Raised if an element with the given name does not exist.
-
update(elements: Iterable[K]) → None¶ Add multiple new elements to the set.
Parameters: - elements :
Iterable Elements to add.
- elements :
- elements :