IndexSet1D#
- class IndexSet1D(iterable=None, /, *, name=None)[source]#
Custom list-like data structure to define index-sets with 1-dim scalar elements.
Requires all elements to be unique scalars (such as int, str, Timestamp, etc.). Supports all mutable sequence operations from builtins.list and rich comparisons from builtins.set.
- Parameters:
- iterableiterable, optional
Input data to be encapsulated in the IndexSet.
- namestr, optional
Name to refer to 1-dim scalar elements - not used internally, and solely for user reference.
- Raises:
- TypeError
If the input contains non-scalar element(s) (any iterable except string).
- ValueError
If the input includes (or creates) duplicate elements.
See also
IndexSetNDFor N-dim tuple elements.
Examples
Constructing empty to populate later:
>>> IndexSet1D() IndexSet1D: []
Constructing with an iterable:
>>> IndexSet1D(range(3)) IndexSet1D: [0, 1, 2]
>>> IndexSet1D(['Delhi', 'Seattle', 'Tokyo'], name='CITY') IndexSet1D: (CITY) ['Delhi', 'Seattle', 'Tokyo']
Methods
IndexSet1D.append(elem, /)Append an element to the end of the IndexSet, in-place.
Remove all elements from the IndexSet.
IndexSet1D.difference(*others)Return a new IndexSet1D with elements in the IndexSet1D that are not in the others.
IndexSet1D.extend(elems, /)Extend the IndexSet by appending elements from an iterable, in-place.
IndexSet1D.index(elem[, start, end])Get the position index of an element in the IndexSet.
IndexSet1D.insert(index, elem, /)Insert an element at a position index in the IndexSet.
IndexSet1D.intersection(*others)Return a new IndexSet1D with elements common to the IndexSet1D and all others.
IndexSet1D.isdisjoint(other)Whether the IndexSet has no elements in common with another iterable, or not.
IndexSet1D.pop([index])Remove and return the element at a position index in the IndexSet.
IndexSet1D.remove(elem, /)Remove an element from the IndexSet, in-place.
Reverse the order of elements of the IndexSet, in-place.
IndexSet1D.sort(*[, key, reverse])Sort the IndexSet in ascending order, in-place.
Return a new IndexSet1D with elements in either the IndexSet1D or other but not both.
IndexSet1D.union(*others)Return a new IndexSet1D with elements from the IndexSet1D and all others.
Attributes
Name to refer to 1-dim scalar elements.