Index-set functionality#
Note
Provided through opti_extensions.* namespace.
IndexSet1D#
Custom list-like data structure to define index-sets with 1-dim scalar elements.
Constructor#
|
Custom list-like data structure to define index-sets with 1-dim scalar elements. |
Attributes#
Name to refer to 1-dim scalar elements. |
Sequence operations#
|
Append an element to the end of the IndexSet, in-place. |
|
Extend the IndexSet by appending elements from an iterable, in-place. |
|
Insert an element at a position index in the IndexSet. |
|
Remove an element from the IndexSet, in-place. |
|
Remove and return the element at a position index in the IndexSet. |
Remove all elements from the IndexSet. |
|
|
Get the position index of an element in the IndexSet. |
|
Sort the IndexSet in ascending order, in-place. |
Reverse the order of elements of the IndexSet, in-place. |
Set comparison#
If two sets have the same elements:
>>> set_a == set_b
If two sets have different elements:
>>> set_a != set_b
If one set is a subset of another:
>>> set_a <= set_b
If one set is a proper subset of another:
>>> set_a < set_b
If one set is a superset of another:
>>> set_a >= set_b
If one set is a proper superset of another:
>>> set_a > set_b
Set operations#
If two sets are disjoint or not:
>>> set_a.isdisjoint(set_b)
Union of two or more sets:
>>> set_a.union(set_b, ...) >>> set_a | set_b | ...
Intersection of two or more sets:
>>> set_a.intersection(set_b, ...) >>> set_a & set_b & ...
Difference of two or more sets:
>>> set_a.difference(set_b, ...) >>> set_a - set_b - ...
Symmetric difference of two sets:
>>> set_a.symmetric_difference(set_b) >>> set_a ^ set_b
Just like set, the non-operator versions of union(), intersection(), difference(), and symmetric_difference() methods will accept any iterable as an argument. In contrast, their operator based counterparts require their arguments to be IndexSet1D.
Dunder methods#
IndexSet1D.__contains__IndexSet1D.__iter__IndexSet1D.__reversed__IndexSet1D.__len__IndexSet1D.__getitem__IndexSet1D.__setitem__IndexSet1D.__delitem__IndexSet1D.__add__IndexSet1D.__iadd__
IndexSetND#
Custom list-like data structure to define index-sets with N-dim tuple elements.
Constructor#
|
Custom list-like data structure to define index-sets with N-dim tuple elements. |
Attributes#
Names to refer to each dimension of N-dim tuple elements. |
Efficient subset selection#
|
Get a subset of the IndexSet with a wildcard pattern. |
|
Squeeze the IndexSet for given dimension indices to get a new IndexSet. |
Sequence operations#
|
Append an element to the end of the IndexSet, in-place. |
|
Extend the IndexSet by appending elements from an iterable, in-place. |
|
Insert an element at a position index in the IndexSet. |
|
Remove an element from the IndexSet, in-place. |
|
Remove and return the element at a position index in the IndexSet. |
Remove all elements from the IndexSet. |
|
|
Get the position index of an element in the IndexSet. |
|
Sort the IndexSet in ascending order, in-place. |
Reverse the order of elements of the IndexSet, in-place. |
Set comparison#
If two sets have the same elements:
>>> set_a == set_b
If two sets have different elements:
>>> set_a != set_b
If one set is a subset of another:
>>> set_a <= set_b
A more efficient approach for sparse sets:
If
set_ais a 3-dim set (of type IndexSetND) and is composed of sparse combinations of elements of three 1-dim setsset_x,set_y, andset_zrespectively (each of type IndexSet1D). Then an efficient subset check forset_acan be directly made with a tuple ofset_x,set_y, andset_z– without having to enumerate all possible combinations from the three.>>> set_a <= (set_x, set_y, set_z)
Can raise the following errors:
LookupError: If the IndexSetND is empty and checked with a tuple of IndexSet1D.ValueError: If the IndexSetND is checked with a tuple of IndexSet1D that is not the same length as the elements of the IndexSetND.
If one set is a proper subset of another:
>>> set_a < set_b
If one set is a superset of another:
>>> set_a >= set_b
If one set is a proper superset of another:
>>> set_a > set_b
Set operations#
If two sets are disjoint or not:
>>> set_a.isdisjoint(set_b)
Union of two or more sets:
>>> set_a.union(set_b, ...) >>> set_a | set_b | ...
Intersection of two or more sets:
>>> set_a.intersection(set_b, ...) >>> set_a & set_b & ...
Difference of two or more sets:
>>> set_a.difference(set_b, ...) >>> set_a - set_b - ...
Symmetric difference of two sets:
>>> set_a.symmetric_difference(set_b) >>> set_a ^ set_b
Just like set, the non-operator versions of union(), intersection(), difference(), and symmetric_difference() methods will accept any iterable as an argument. In contrast, their operator based counterparts require their arguments to be IndexSetND.
Dunder methods#
IndexSetND.__contains__IndexSetND.__iter__IndexSetND.__reversed__IndexSetND.__len__IndexSetND.__getitem__IndexSetND.__setitem__IndexSetND.__delitem__IndexSetND.__add__IndexSetND.__iadd__
Casting from pandas Series/DataFrame/Index#
Methods to cast pandas Series/DataFrame/Index into IndexSet1D/IndexSetND are
provided through the custom .opti accessor.
Cast a Series into an IndexSet1D. |
|
Cast a DataFrame into an IndexSet1D/IndexSetND. |
|
Cast an Index into an IndexSet1D/IndexSetND. |