Index-set functionality#

IndexSet1D#

Custom list-like data structure to define index-sets with 1-dim scalar elements.

Constructor#

IndexSet1D([iterable, name])

Custom list-like data structure to define index-sets with 1-dim scalar elements.

Attributes#

IndexSet1D.name

Name to refer to 1-dim scalar elements.

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
    

Sequence operations#

IndexSet1D.append(elem, /)

Append an element to the end of the IndexSet, in-place.

IndexSet1D.extend(elems, /)

Extend the IndexSet by appending elements from an iterable, in-place.

IndexSet1D.insert(index, elem, /)

Insert an element at a position index in the IndexSet.

IndexSet1D.remove(elem, /)

Remove an element from the IndexSet, in-place.

IndexSet1D.pop([index])

Remove and return the element at a position index in the IndexSet.

IndexSet1D.clear()

Remove all elements from the IndexSet.

IndexSet1D.index(elem[, start, end])

Get the position index of an element in the IndexSet.

IndexSet1D.sort(*[, key, reverse])

Sort the IndexSet in ascending order, in-place.

IndexSet1D.reverse()

Reverse the order of elements of the IndexSet, in-place.

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#

IndexSetND(*iterables[, names])

Custom list-like data structure to define index-sets with N-dim tuple elements.

Attributes#

IndexSetND.names

Names to refer to each dimension of N-dim tuple elements.

Efficient subset selection#

IndexSetND.subset(*pattern)

Get a subset of the IndexSet with a wildcard pattern.

IndexSetND.squeeze(*indices[, names])

Squeeze the IndexSet for given dimension indices to get a new IndexSet.

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_a is a 3-dim set (of type IndexSetND) and is composed of sparse combinations of elements of three 1-dim sets set_x, set_y, and set_z respectively (each of type IndexSet1D). Then an efficient subset check for set_a can be directly made with a tuple of set_x, set_y, and set_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
    

Sequence operations#

IndexSetND.append(elem, /)

Append an element to the end of the IndexSet, in-place.

IndexSetND.extend(elems, /)

Extend the IndexSet by appending elements from an iterable, in-place.

IndexSetND.insert(index, elem, /)

Insert an element at a position index in the IndexSet.

IndexSetND.remove(elem, /)

Remove an element from the IndexSet, in-place.

IndexSetND.pop([index])

Remove and return the element at a position index in the IndexSet.

IndexSetND.clear()

Remove all elements from the IndexSet.

IndexSetND.index(elem[, start, end])

Get the position index of an element in the IndexSet.

IndexSetND.sort(*[, key, reverse])

Sort the IndexSet in ascending order, in-place.

IndexSetND.reverse()

Reverse the order of elements of the IndexSet, in-place.

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 .dex accessor.

Series.dex.to_indexset()

Cast a Series into an IndexSet1D.

DataFrame.dex.to_indexset()

Cast a DataFrame into an IndexSet1D/IndexSetND.

Index.dex.to_indexset()

Cast an Index into an IndexSet1D/IndexSetND.