Detail: IndexHierarchyGO: Constructor

Overview: IndexHierarchyGO: Constructor

IndexHierarchyGO.__init__(indices, *, indexers=array([], dtype=int64), name=<object object>, blocks=None, own_blocks=False)

Initializer.

Parameters:
  • indices – list of Index objects

  • indexers – a 2D indexer array

  • name – name of the IndexHierarchy

  • blocks

  • own_blocks

>>> a = np.array([[0, 0, 1, 1], [0, 1, 0, 1]])
>>> a.flags.writeable = False
>>> sf.IndexHierarchyGO((sf.Index(('a', 'b')), sf.Index((1024, 2048))), indexers=a)
<IndexHierarchyGO>
a                  1024
a                  2048
b                  1024
b                  2048
<<U1>              <int64>
classmethod IndexHierarchyGO.from_index_items(items, *, index_constructor=None, name=None)

Given an iterable of pairs of label, IndexBase, produce an IndexHierarchy where the labels are depth 0, the indices are depth 1. While the provided IndexBase can be Index or IndexHierarchy, across all pairs all depths must be the same.

Parameters:
  • items – iterable of pairs of label, IndexBase.

  • index_constructor – Optionally provide index constructor for outermost index.

>>> ix1 = sf.Index(('a', 'b', 'c'), name='x')
>>> ix1
<Index: x>
a
b
c
<<U1>
>>> ix2 = sf.Index((1024, 2048, 4096), name='y')
>>> ix2
<Index: y>
1024
2048
4096
<int64>
>>> ih1 = sf.IndexHierarchyGO.from_index_items(((ix1.name, ix1), (ix2.name, ix2)), name='ih1')
>>> ih1
<IndexHierarchyGO: ih1>
x                       a
x                       b
x                       c
y                       1024
y                       2048
y                       4096
<<U1>                   <object>
>>> ih2 = sf.IndexHierarchyGO.from_index_items(((ix2.name, ix2), (ix1.name, ix1)), name='ih2')
>>> ih2
<IndexHierarchyGO: ih2>
y                       1024
y                       2048
y                       4096
x                       a
x                       b
x                       c
<<U1>                   <object>
>>> sf.IndexHierarchyGO.from_index_items(((ih1.name, ih1), (ih2.name, ih2)))
<IndexHierarchyGO>
ih1                x     a
ih1                x     b
ih1                x     c
ih1                y     1024
ih1                y     2048
ih1                y     4096
ih2                y     1024
ih2                y     2048
ih2                y     4096
ih2                x     a
ih2                x     b
ih2                x     c
<<U3>              <<U1> <object>
classmethod IndexHierarchyGO.from_labels(labels, *, name=None, reorder_for_hierarchy=False, index_constructors=None, depth_reference=None, continuation_token=<object object>)

Construct an IndexHierarchy from an iterable of labels, where each label is tuple defining the component labels for all hierarchies.

Parameters:
  • labels – an iterator or generator of tuples.

  • *

  • name

  • reorder_for_hierarchy – an optional argument that will ensure the resulting index is arranged in a tree-like structure.

  • index_constructors

  • depth_reference

  • continuation_token – a Hashable that will be used as a token to identify when a value in a label should use the previously encountered value at the same depth.

Returns:

IndexHierarchy

>>> sf.IndexHierarchyGO.from_labels((('a', 1024, True), ('a', 2048, True), ('a', 2048, False), ('b', 1024, True)), name='x')
<IndexHierarchyGO: x>
a                     1024    True
a                     2048    True
a                     2048    False
b                     1024    True
<<U1>                 <int64> <bool>
classmethod IndexHierarchyGO.from_labels_delimited(labels, *, delimiter=' ', name=None, index_constructors=None)

Construct an IndexHierarchy from an iterable of labels, where each label is string defining the component labels for all hierarchies using a string delimiter. All components after splitting the string by the delimited will be literal evaled to produce proper types; thus, strings must be quoted.

Parameters:

labels – an iterator or generator of tuples.

Returns:

static_frame.IndexHierarchy

>>> sf.IndexHierarchyGO.from_labels_delimited(("'a'|1024|False", "'b'|1024|True", "'b'|2048|False"), delimiter='|')
<IndexHierarchyGO>
a                  1024    False
b                  1024    True
b                  2048    False
<<U1>              <int64> <bool>
classmethod IndexHierarchyGO.from_names(names)

Construct a zero-length IndexHierarchy from an iterable of names, where the length of names defines the zero-length depth.

Parameters:

names – Iterable of hashable names per depth.

>>> sf.IndexHierarchyGO.from_names(('x', 'y', 'z'))
<IndexHierarchyGO: ('x', 'y', 'z')>
<float64>                           <float64> <float64>
classmethod IndexHierarchyGO.from_pandas(value)

Given a Pandas index, return the appropriate IndexBase derived class.

>>> mi = pd.MultiIndex.from_product((('a', 'b'), (1024, 2048)))
>>> sf.IndexHierarchyGO.from_pandas(mi)
<IndexHierarchyGO>
a                  1024
a                  2048
b                  1024
b                  2048
<object>           <int64>
classmethod IndexHierarchyGO.from_product(*levels, name=None, index_constructors=None)

Given groups of iterables, return an IndexHierarchy made of the product of a values in those groups, where the first group is the top-most hierarchy.

Parameters:
  • *levels – index initializers (or Index instances) for each level

  • name

  • index_consructors

Returns:

static_frame.IndexHierarchy

>>> sf.IndexHierarchyGO.from_product(('a', 'b'), ('1517-04-01', '1620-11-21'), name='x', index_constructors=(sf.Index, sf.IndexDate))
<IndexHierarchyGO: x>
a                     1517-04-01
a                     1620-11-21
b                     1517-04-01
b                     1620-11-21
<<U1>                 <datetime64[D]>
classmethod IndexHierarchyGO.from_tree(tree, *, name=None, index_constructors=None)

Convert into a IndexHierarchy a dictionary defining keys to either iterables or nested dictionaries of the same.

Returns:

static_frame.IndexHierarchy

>>> sf.IndexHierarchyGO.from_tree({'a': {1024: (False, True), 2048: (True,)}})
<IndexHierarchyGO>
a                  1024    False
a                  1024    True
a                  2048    True
<<U1>              <int64> <bool>
classmethod IndexHierarchyGO.from_values_per_depth(values, *, name=None, depth_reference=None, index_constructors=None)

Construct an IndexHierarchy from a 2D NumPy array, or a collection of 1D arrays per depth.

Very similar implementation to _from_type_blocks(), but avoids creating TypeBlocks instance.

Returns:

IndexHierarchy

>>> sf.IndexHierarchyGO.from_values_per_depth((('a', 'a', 'b', 'b'), (0, 1, 0, 1)))
<IndexHierarchyGO>
a                  0
a                  1
b                  0
b                  1
<<U1>              <int64>
>>> sf.IndexHierarchyGO.from_values_per_depth((range(0, 12, 2), range(6)))
<IndexHierarchyGO>
0                  0
2                  1
4                  2
6                  3
8                  4
10                 5
<int64>            <int64>

IndexHierarchyGO: Constructor | Exporter | Attribute | Method | Dictionary-Like | Display | Selector | Iterator | Operator Binary | Operator Unary | Accessor Values | Accessor Datetime | Accessor String | Accessor Transpose | Accessor Regular Expression | Accessor Hashlib | Accessor Type Clinic