Detail: IndexHierarchyGO: Method

Overview: IndexHierarchyGO: Method

IndexHierarchyGO.__array__(dtype=None)

Support the __array__ interface, returning an array of values.

>>> ih = sf.IndexHierarchyGO.from_labels(((0, 1024, 32), (1, -2048, 32), (1, 1024, 32)), name=('x', 'y', 'z'))
>>> ih.__array__()
[[    0  1024    32]
 [    1 -2048    32]
 [    1  1024    32]]
IndexHierarchyGO.__array_ufunc__(ufunc, method, *args, **kwargs)

Support for NumPy elements or arrays on the left hand of binary operators.

>>> ih = sf.IndexHierarchyGO.from_labels(((0, 1024, 32), (1, -2048, 32), (1, 1024, 32)), name=('x', 'y', 'z'))
>>> ih
<IndexHierarchyGO: ('x', 'y', 'z')>
0                                   1024    32
1                                   -2048   32
1                                   1024    32
<int64>                             <int64> <int64>
>>> np.array((0, 1, 0)) * ih
[[    0  1024     0]
 [    0 -2048     0]
 [    0  1024     0]]
IndexHierarchyGO.__bool__()

Raises ValueError to prohibit ambiguous use of truethy evaluation.

>>> s = sf.IndexHierarchyGO.from_labels(((0, 1024, 32), (1, -2048, 32), (1, 1024, 32)), name=('x', 'y', 'z'))
>>> bool(s)
ValueError('The truth value of a container is ambiguous. For a truthy indicator of non-empty status, use the `size` attribute.')
IndexHierarchyGO.__copy__()

Return a shallow copy of this IndexHierarchy.

>>> import copy
>>> ih = sf.IndexHierarchyGO.from_labels(((0, 1024, 32), (1, -2048, 32), (1, 1024, 32)), name=('x', 'y', 'z'))
>>> copy.copy(ih)
<IndexHierarchyGO: ('x', 'y', 'z')>
0                                   1024    32
1                                   -2048   32
1                                   1024    32
<int64>                             <int64> <int64>
IndexHierarchyGO.__deepcopy__(memo)

Return a deep copy of this IndexHierarchy.

>>> import copy
>>> ih = sf.IndexHierarchyGO.from_labels(((0, 1024, 32), (1, -2048, 32), (1, 1024, 32)), name=('x', 'y', 'z'))
>>> copy.deepcopy(ih)
<IndexHierarchyGO: ('x', 'y', 'z')>
0                                   1024    32
1                                   -2048   32
1                                   1024    32
<int64>                             <int64> <int64>
IndexHierarchyGO.__len__()
>>> ih = sf.IndexHierarchyGO.from_labels(((0, 1024, 32), (1, -2048, 32), (1, 1024, 32)), name=('x', 'y', 'z'))
>>> len(ih)
3
IndexHierarchyGO.all(axis=0, skipna=True, out=None)

Logical and over values along the specified axis.

Parameters
  • axis – Axis, defaulting to axis 0.

  • skipna – Skip missing (NaN) values, defaulting to True.

>>> ih = sf.IndexHierarchyGO.from_labels(((False, True, True), (True, True, True), (False, True, False)), name=('x', 'y', 'z'))
>>> ih.all()
NotImplementedError('<function ufunc_all at 0x7fbd501e4310> for IndexHierarchyGO is not defined; convert to `Frame`.')
IndexHierarchyGO.any(axis=0, skipna=True, out=None)

Logical or over values along the specified axis.

Parameters
  • axis – Axis, defaulting to axis 0.

  • skipna – Skip missing (NaN) values, defaulting to True.

>>> ih = sf.IndexHierarchyGO.from_labels(((False, True, True), (True, True, True), (False, True, False)), name=('x', 'y', 'z'))
>>> ih.any()
NotImplementedError('<function ufunc_any at 0x7fbd501e43a0> for IndexHierarchyGO is not defined; convert to `Frame`.')
IndexHierarchyGO.append(value)[source]

Append a single label to this IndexHierarchyGO in-place

>>> ih = sf.IndexHierarchyGO.from_labels((('a', 1024, True), ('a', 2048, True), ('a', 2048, False), ('b', 1024, True)), name='x')
>>> ih.append(('b', 4096, True))
>>> ih
<IndexHierarchyGO: x>
a                     1024    True
a                     2048    True
a                     2048    False
b                     1024    True
b                     4096    True
<<U1>                 <int64> <bool>
IndexHierarchyGO.astype[key](dtypes, *, consolidate_blocks)
IndexHierarchyGO.astype

Retype one or more depths. Can be used as as function to retype the entire IndexHierarchy; alternatively, a __getitem__ interface permits retyping selected depths.

Parameters

dtype – A value suitable for specyfying a NumPy dtype, such as a Python type (float), NumPy array protocol strings (‘f8’), or a dtype instance.

InterfaceAsType.__getitem__(key)[source]

Selector of columns by label.

Parameters

key – A loc selector, either a label, a list of labels, a slice of labels, or a Boolean array.

>>> ih = sf.IndexHierarchyGO.from_labels((('a', 1024, '1517-04-01'), ('a', 2048, '1789-12-31'), ('b', 0, '1620-11-21')), index_constructors=(sf.Index, sf.Index, sf.IndexDate), name=('x', 'y', 'z'))
>>> ih
<IndexHierarchyGO: ('x', 'y', 'z')>
a                                   1024    1517-04-01
a                                   2048    1789-12-31
b                                   0       1620-11-21
<<U1>                               <int64> <datetime64[D]>
>>> ih.astype[1](bool)
<IndexHierarchyGO>
a                  True   1517-04-01
a                  True   1789-12-31
b                  False  1620-11-21
<<U1>              <bool> <datetime64[D]>
IndexHierarchyGO.astype(dtype, *, consolidate_blocks)
astype

Retype one or more depths. Can be used as as function to retype the entire IndexHierarchy; alternatively, a __getitem__ interface permits retyping selected depths.

Parameters

dtype – A value suitable for specyfying a NumPy dtype, such as a Python type (float), NumPy array protocol strings (‘f8’), or a dtype instance.

InterfaceAsType.__call__(dtype, *, consolidate_blocks=False)[source]

Apply a single dtype to all columns.

>>> ih = sf.IndexHierarchyGO.from_labels(((False, True, True), (True, True, True), (False, True, False)), name=('x', 'y', 'z'))
>>> ih
<IndexHierarchyGO: ('x', 'y', 'z')>
False                               True   True
True                                True   True
False                               True   False
<bool>                              <bool> <bool>
>>> ih.astype(str)
<IndexHierarchyGO>
False              True  True
True               True  True
False              True  False
<<U5>              <<U5> <<U5>
IndexHierarchyGO.copy()

Return a shallow copy of this IndexHierarchy.

>>> ih = sf.IndexHierarchyGO.from_labels(((0, 1024, 32), (1, -2048, 32), (1, 1024, 32)), name=('x', 'y', 'z'))
>>> ih.copy()
<IndexHierarchyGO: ('x', 'y', 'z')>
0                                   1024    32
1                                   -2048   32
1                                   1024    32
<int64>                             <int64> <int64>
IndexHierarchyGO.cumprod(axis=0, skipna=True)

Return the cumulative product over the specified axis.

Parameters
  • axis – Axis, defaulting to axis 0.

  • skipna – Skip missing (NaN) values, defaulting to True.

>>> ih = sf.IndexHierarchyGO.from_labels(((0, 1024, 32), (1, -2048, 32), (1, 1024, 32)), name=('x', 'y', 'z'))
>>> ih.cumprod()
NotImplementedError('<function cumprod at 0x7fbdfe7f99d0> for IndexHierarchyGO is not defined; convert to `Frame`.')
IndexHierarchyGO.cumsum(axis=0, skipna=True)

Return the cumulative sum over the specified axis.

Parameters
  • axis – Axis, defaulting to axis 0.

  • skipna – Skip missing (NaN) values, defaulting to True.

>>> ih = sf.IndexHierarchyGO.from_labels(((0, 1024, 32), (1, -2048, 32), (1, 1024, 32)), name=('x', 'y', 'z'))
>>> ih.cumsum()
NotImplementedError('<function cumsum at 0x7fbdfe7f5f70> for IndexHierarchyGO is not defined; convert to `Frame`.')
IndexHierarchyGO.difference(*others)

Perform difference with another Index, container, or NumPy array. Retains order.

>>> ih1 = sf.IndexHierarchyGO.from_labels((('a', 1024, True), ('a', 2048, True), ('a', 2048, False)), name='x')
>>> ih2 = sf.IndexHierarchyGO.from_labels((('a', 1024, True), ('b', 1024, True)), name='y')
>>> ih1.difference(ih2)
<IndexHierarchyGO>
a                  2048    False
a                  2048    True
<<U1>              <int64> <bool>
IndexHierarchyGO.dropfalsy(*, condition=<function all>)

Return a new obj:IndexHierarchy after removing labels where any or all values are falsy. The condition is determined by a NumPy ufunc that process the Boolean array returned by isna(); the default is np.all.

Parameters
  • *,

  • condition

>>> ih = sf.IndexHierarchyGO.from_labels((('a', 1024, True), ('', 0, False), ('b', 1024, True)), name='x')
>>> ih
<IndexHierarchyGO: x>
a                     1024    True
                      0       False
b                     1024    True
<<U1>                 <int64> <bool>
>>> ih.dropfalsy()
<IndexHierarchyGO: x>
a                     1024    True
b                     1024    True
<<U1>                 <int64> <bool>
IndexHierarchyGO.dropna(*, condition=<function all>)

Return a new obj:IndexHierarchy after removing labels where any or all values are NA (NaN or None). The condition is determined by a NumPy ufunc that process the Boolean array returned by isna(); the default is np.all.

Parameters
  • *,

  • condition

>>> ih = sf.IndexHierarchyGO.from_labels(((0, 1024), (1, 2048), (np.nan, np.nan)), name=('x', 'y'))
>>> ih
<IndexHierarchyGO: ('x', 'y')>
0.0                            1024.0
1.0                            2048.0
nan                            nan
<float64>                      <float64>
>>> ih.dropna()
<IndexHierarchyGO: ('x', 'y')>
0.0                            1024.0
1.0                            2048.0
<float64>                      <float64>
IndexHierarchyGO.equals(other, *, compare_name=False, compare_dtype=False, compare_class=False, skipna=True)

Return a bool from comparison to any other object.

Parameters
  • compare_name – Include equality of the container’s name (and all composed containers) in the comparison.

  • compare_dtype – Include equality of the container’s dtype (and all composed containers) in the comparison.

  • compare_class – Include equality of the container’s class (and all composed containers) in the comparison.

  • skipna – If True, comparisons between missing values are equal.

>>> ih1 = sf.IndexHierarchyGO.from_labels((('a', 1024, True), ('a', 2048, True), ('a', 2048, False)), name='x')
>>> ih2 = sf.IndexHierarchyGO.from_labels((('a', 1024, True), ('b', 1024, True)), name='y')
>>> ih1.equals(ih2)
False
IndexHierarchyGO.extend(other)[source]

Extend this IndexHierarchyGO in-place

>>> ih1 = sf.IndexHierarchyGO.from_labels((('a', 1024, True), ('a', 2048, True), ('a', 2048, False), ('b', 1024, True)), name='x')
>>> ih2 = sf.IndexHierarchyGO.from_labels((('a', 1024, True), ('', 0, False), ('b', 1024, True)), name='x')
>>> ih1.extend(ih2)
>>> ih1
ErrorInitIndexNonUnique(('a', 1024, True))
IndexHierarchyGO.fillfalsy(value)

Return an IndexHierarchy after replacing falsy values with the supplied value.

Parameters

value – Value to be used to replace missing values (NaN or None).

>>> ih = sf.IndexHierarchyGO.from_labels((('a', 1024, True), ('', 0, False), ('b', 1024, True)), name='x')
>>> ih
<IndexHierarchyGO: x>
a                     1024    True
                      0       False
b                     1024    True
<<U1>                 <int64> <bool>
>>> ih.fillfalsy(-1)
<IndexHierarchyGO: x>
a                     1024    True
-1                    -1      -1
b                     1024    True
<object>              <int64> <object>
IndexHierarchyGO.fillna(value)

Return an IndexHierarchy after replacing NA (NaN or None) with the supplied value.

Parameters

value – Value to be used to replace missing values (NaN or None).

>>> ih = sf.IndexHierarchyGO.from_labels(((0, 1024), (1, 2048), (np.nan, np.nan)), name=('x', 'y'))
>>> ih
<IndexHierarchyGO: ('x', 'y')>
0.0                            1024.0
1.0                            2048.0
nan                            nan
<float64>                      <float64>
>>> ih.fillna(0)
<IndexHierarchyGO: ('x', 'y')>
0.0                            1024.0
1.0                            2048.0
0.0                            0.0
<float64>                      <float64>
IndexHierarchyGO.flat()

Return a flat, one-dimensional index of tuples for each level.

>>> ih = sf.IndexHierarchyGO.from_labels((('a', 1024, '1517-04-01'), ('a', 2048, '1789-12-31'), ('b', 0, '1620-11-21')), index_constructors=(sf.Index, sf.Index, sf.IndexDate), name=('x', 'y', 'z'))
>>> ih
<IndexHierarchyGO: ('x', 'y', 'z')>
a                                   1024    1517-04-01
a                                   2048    1789-12-31
b                                   0       1620-11-21
<<U1>                               <int64> <datetime64[D]>
>>> ih.flat().display_wide()
<IndexGO: ('x', 'y', 'z')>
('a', 1024, numpy.datetime64('1517-04-01'))
('a', 2048, numpy.datetime64('1789-12-31'))
('b', 0, numpy.datetime64('1620-11-21'))
<object>
IndexHierarchyGO.head(count=5)

Return a Index consisting only of the top elements as specified by count.

Parameters

count – Number of elements to be returned from the top of the Index

>>> ih = sf.IndexHierarchyGO.from_product(('a', 'b', 'c'), ('1517-04-01', '1620-11-21'), name='x', index_constructors=(sf.Index, sf.IndexDate))
>>> ih
<IndexHierarchyGO: x>
a                     1517-04-01
a                     1620-11-21
b                     1517-04-01
b                     1620-11-21
c                     1517-04-01
c                     1620-11-21
<<U1>                 <datetime64[D]>
>>> ih.head(2)
<IndexHierarchyGO: x>
a                     1517-04-01
a                     1620-11-21
<<U1>                 <datetime64[D]>
IndexHierarchyGO.iloc_searchsorted(values, *, side_left=True)

Given a sorted Series, return the iloc (integer) position(s) at which insertion in values would retain sort order.

Parameters
  • values – a single value, or iterable of values.

  • side_left – If True, the index of the first suitable location found is given, else return the last such index. If matching an existing value, side_left==True will return that position, side_left==Right will return the next position (or the length).

>>> ih = sf.IndexHierarchyGO.from_product(('a', 'b', 'c'), ('1517-04-01', '1620-11-21'), name='x', index_constructors=(sf.Index, sf.IndexDate))
>>> ih
<IndexHierarchyGO: x>
a                     1517-04-01
a                     1620-11-21
b                     1517-04-01
b                     1620-11-21
c                     1517-04-01
c                     1620-11-21
<<U1>                 <datetime64[D]>
>>> ih.iloc_searchsorted(('b', np.datetime64('1620-11-21')))
3
IndexHierarchyGO.index_at_depth(depth_level=0)

Return an index, or a tuple of indices for the depth_level specified.

Parameters

depth_level – a single depth level, or iterable depth of depth levels.

>>> ih = sf.IndexHierarchyGO.from_labels((('a', 1024, '1517-04-01'), ('a', 2048, '1789-12-31'), ('b', 0, '1620-11-21')), index_constructors=(sf.Index, sf.Index, sf.IndexDate), name=('x', 'y', 'z'))
>>> ih.index_at_depth(0)
<IndexGO>
a
b
<<U1>
>>> ih.index_at_depth([2, 0])
(<IndexDateGO>
1517-04-01
1789-12-31
1620-11-21
<datetime64[D]>, <IndexGO>
a
b
<<U1>)
IndexHierarchyGO.indexer_at_depth(depth_level=0)

Return the indexers for the depth_level specified. Array will 2D if multiple depths are selected.

Parameters

depth_level – a single depth level, or iterable depth of depth levels.

>>> ih = sf.IndexHierarchyGO.from_labels((('a', 1024, '1517-04-01'), ('a', 2048, '1789-12-31'), ('b', 0, '1620-11-21')), index_constructors=(sf.Index, sf.Index, sf.IndexDate), name=('x', 'y', 'z'))
>>> ih.indexer_at_depth(0)
[0 0 1]
>>> ih.indexer_at_depth([2, 0])
[[0 1 2]
 [0 0 1]]
IndexHierarchyGO.intersection(*others)

Perform intersection with one or many Index, container, or NumPy array. Identical comparisons retain order.

>>> ih1 = sf.IndexHierarchyGO.from_labels((('a', 1024, True), ('a', 2048, True), ('a', 2048, False)), name='x')
>>> ih2 = sf.IndexHierarchyGO.from_labels((('a', 1024, True), ('b', 1024, True)), name='y')
>>> ih1.intersection(ih2)
<IndexHierarchyGO>
a                  1024    True
<<U1>              <int64> <bool>
IndexHierarchyGO.isin(other)

Return a Boolean array showing True where one or more of the passed in iterable of labels is found in the index.

>>> ih = sf.IndexHierarchyGO.from_product(('a', 'b', 'c'), ('1517-04-01', '1620-11-21'), name='x', index_constructors=(sf.Index, sf.IndexDate))
>>> ih.isin((('c', np.datetime64('1517-04-01')), ('a', np.datetime64('1620-11-21'))))
[False  True False False  True False]
IndexHierarchyGO.label_widths_at_depth(depth_level=0)

A generator of pairs, where each pair is the label and the count of that label found at the depth specified by depth_level.

Parameters

depth_level – a depth level, starting from zero.

>>> ih = sf.IndexHierarchyGO.from_labels((('a', 1024, True), ('a', 2048, True), ('a', 2048, False), ('b', 1024, True)), name='x')
>>> ih
<IndexHierarchyGO: x>
a                     1024    True
a                     2048    True
a                     2048    False
b                     1024    True
<<U1>                 <int64> <bool>
>>> tuple(ih.label_widths_at_depth(0))
(('a', 3), ('b', 1))
>>> tuple(ih.label_widths_at_depth(1))
((1024, 1), (2048, 2), (1024, 1))
>>> tuple(ih.label_widths_at_depth(2))
((True, 1), (True, 1), (False, 1), (True, 1))
IndexHierarchyGO.level_add(level, *, index_constructor=None)

Return an IndexHierarchy with a new root (outer) level added.

>>> ih = sf.IndexHierarchyGO.from_labels(((0, 1024), (1, 2048), (np.nan, np.nan)), name=('x', 'y'))
>>> ih
<IndexHierarchyGO: ('x', 'y')>
0.0                            1024.0
1.0                            2048.0
nan                            nan
<float64>                      <float64>
>>> ih.level_add('A')
<IndexHierarchyGO: ('x', 'y')>
A                              0.0       1024.0
A                              1.0       2048.0
A                              nan       nan
<<U1>                          <float64> <float64>
IndexHierarchyGO.level_drop(count=1)

Return an IndexHierarchy with one or more leaf levels removed.

Parameters

count – A positive value is the number of depths to remove from the root (outer) side of the hierarchy; a negative value is the number of depths to remove from the leaf (inner) side of the hierarchy.

>>> ih = sf.IndexHierarchyGO.from_labels((('a', 1024, '1517-04-01'), ('a', 2048, '1789-12-31'), ('b', 0, '1620-11-21')), index_constructors=(sf.Index, sf.Index, sf.IndexDate), name=('x', 'y', 'z'))
>>> ih
<IndexHierarchyGO: ('x', 'y', 'z')>
a                                   1024    1517-04-01
a                                   2048    1789-12-31
b                                   0       1620-11-21
<<U1>                               <int64> <datetime64[D]>
>>> ih.level_drop()
<IndexHierarchyGO: ('y', 'z')>
1024                           1517-04-01
2048                           1789-12-31
0                              1620-11-21
<int64>                        <datetime64[D]>
IndexHierarchyGO.loc_searchsorted(values, *, side_left=True, fill_value=nan)

Given a sorted Series, return the loc (label) position(s) at which insertion in values would retain sort order.

Parameters
  • values – a single value, or iterable of values.

  • side_left – If True, the index of the first suitable location found is given, else return the last such index. If matching an existing value, side_left==True will return that position, side_left==Right will return the next position (or the length).

  • fill_value – A value to be used to fill the label beyond the last label.

>>> ih = sf.IndexHierarchyGO.from_product(('a', 'b', 'c'), ('1517-04-01', '1620-11-21'), name='x', index_constructors=(sf.Index, sf.IndexDate))
>>> ih
<IndexHierarchyGO: x>
a                     1517-04-01
a                     1620-11-21
b                     1517-04-01
b                     1620-11-21
c                     1517-04-01
c                     1620-11-21
<<U1>                 <datetime64[D]>
>>> ih.loc_searchsorted(('b', np.datetime64('1620-11-21')))
('b', numpy.datetime64('1620-11-21'))
IndexHierarchyGO.loc_to_iloc(key)

Given a label (loc) style key (either a label, a list of labels, a slice, an HLoc object, or a Boolean selection), return the index position (iloc) style key. Keys that are not found will raise a KeyError or a sf.LocInvalid error.

Parameters

key – a label key.

>>> ih = sf.IndexHierarchyGO.from_labels((('a', 1024, True), ('a', 2048, True), ('a', 2048, False), ('b', 1024, True)), name='x')
>>> ih
<IndexHierarchyGO: x>
a                     1024    True
a                     2048    True
a                     2048    False
b                     1024    True
<<U1>                 <int64> <bool>
>>> ih.loc_to_iloc(('b', 1024, True))
3
>>> ih.loc_to_iloc([('a', 1024, True), ('b', 1024, True)])
[0, 3]
>>> ih.loc_to_iloc(slice(('a', 2048, False), None))
slice(2, None, None)
IndexHierarchyGO.max(axis=0, skipna=True)

Return the maximum along the specified axis.

Parameters
  • axis – Axis, defaulting to axis 0.

  • skipna – Skip missing (NaN) values, defaulting to True.

>>> ih = sf.IndexHierarchyGO.from_labels(((0, 1024, 32), (1, -2048, 32), (1, 1024, 32)), name=('x', 'y', 'z'))
>>> ih.max()
[   1 1024   32]
IndexHierarchyGO.mean(axis=0, skipna=True, out=None)

Return the mean along the specified axis.

Parameters
  • axis – Axis, defaulting to axis 0.

  • skipna – Skip missing (NaN) values, defaulting to True.

>>> ih = sf.IndexHierarchyGO.from_labels(((0, 1024, 32), (1, -2048, 32), (1, 1024, 32)), name=('x', 'y', 'z'))
>>> ih.mean()
NotImplementedError('<function mean at 0x7fbdfe7fd0d0> for IndexHierarchyGO is not defined; convert to `Frame`.')
IndexHierarchyGO.median(axis=0, skipna=True, out=None)

Return the median along the specified axis.

Parameters
  • axis – Axis, defaulting to axis 0.

  • skipna – Skip missing (NaN) values, defaulting to True.

>>> ih = sf.IndexHierarchyGO.from_labels(((0, 1024, 32), (1, -2048, 32), (1, 1024, 32)), name=('x', 'y', 'z'))
>>> ih.median()
NotImplementedError('<function median at 0x7fbdfe680670> for IndexHierarchyGO is not defined; convert to `Frame`.')
IndexHierarchyGO.min(axis=0, skipna=True, out=None)

Return the minimum along the specified axis.

Parameters
  • axis – Axis, defaulting to axis 0.

  • skipna – Skip missing (NaN) values, defaulting to True.

>>> ih = sf.IndexHierarchyGO.from_labels(((0, 1024, 32), (1, -2048, 32), (1, 1024, 32)), name=('x', 'y', 'z'))
>>> ih.min()
[   0 1024   32]
IndexHierarchyGO.prod(axis=0, skipna=True, out=None)

Return the product along the specified axis.

Parameters
  • axis – Axis, defaulting to axis 0.

  • skipna – Skip missing (NaN) values, defaulting to True.

>>> ih = sf.IndexHierarchyGO.from_labels(((0, 1024, 32), (1, -2048, 32), (1, 1024, 32)), name=('x', 'y', 'z'))
>>> ih.prod()
NotImplementedError('<function prod at 0x7fbdfe7f9820> for IndexHierarchyGO is not defined; convert to `Frame`.')
IndexHierarchyGO.rehierarch(depth_map, *, index_constructors=None)

Return a new IndexHierarchy that conforms to the new depth assignments given be depth_map.

>>> ih = sf.IndexHierarchyGO.from_labels((('b', 1024, True), ('a', 1024, True), ('a', 2048, True), ('a', 2048, False)), name='x')
>>> ih.rehierarch([2, 0, 1])
<IndexHierarchyGO>
True               b     1024
True               a     1024
True               a     2048
False              a     2048
<bool>             <<U1> <int64>
IndexHierarchyGO.relabel(mapper)

Return a new IndexHierarchy with labels replaced by the callable or mapping; order will be retained. If a mapping is used, the mapping should map tuple representation of labels, and need not map all origin keys.

>>> ih = sf.IndexHierarchyGO.from_labels((('b', 1024, True), ('a', 1024, True), ('a', 2048, True), ('a', 2048, False)), name='x')
>>> ih.relabel(lambda l: (l[0], l[1], str(l[2])[0]))
<IndexHierarchyGO: x>
b                     1024    T
a                     1024    T
a                     2048    T
a                     2048    F
<<U1>                 <int64> <<U1>
IndexHierarchyGO.relabel_at_depth(mapper, depth_level=0)

Return a new IndexHierarchy after applying mapper to a level or each individual level specified by depth_level.

mapper can be a callable, mapping, or iterable.
  • If a callable, it must accept a single hashable, and return a single hashable.

  • If a mapping, it must map a single hashable to a single hashable.

  • If a iterable, it must be the same length as self.

This call:

>>> index.relabel_at_depth(mapper, depth_level=[0, 1, 2])

is equivalent to:

>>> for level in [0, 1, 2]:
>>>     index = index.relabel_at_depth(mapper, depth_level=level)

albeit more efficient.

>>> ih = sf.IndexHierarchyGO.from_labels((('b', 1024, True), ('a', 1024, True), ('a', 2048, True), ('a', 2048, False)), name='x')
>>> ih.relabel_at_depth(lambda l: str(l)[0], depth_level=[1, 2])
<IndexHierarchyGO: x>
b                     1     T
a                     1     T
a                     2     T
a                     2     F
<<U1>                 <<U1> <<U1>
IndexHierarchyGO.rename(name)

Return a new IndexHierarchy with an updated name attribute.

>>> ih = sf.IndexHierarchyGO.from_labels((('a', 1024, True), ('a', 2048, True), ('a', 2048, False), ('b', 1024, True)), name='x')
>>> ih.rename('y')
<IndexHierarchyGO: y>
a                     1024    True
a                     2048    True
a                     2048    False
b                     1024    True
<<U1>                 <int64> <bool>
IndexHierarchyGO.roll(shift)

Return an IndexHierarchy with values rotated forward and wrapped around (with a positive shift) or backward and wrapped around (with a negative shift).

>>> ih = sf.IndexHierarchyGO.from_product(('a', 'b', 'c'), ('1517-04-01', '1620-11-21'), name='x', index_constructors=(sf.Index, sf.IndexDate))
>>> ih
<IndexHierarchyGO: x>
a                     1517-04-01
a                     1620-11-21
b                     1517-04-01
b                     1620-11-21
c                     1517-04-01
c                     1620-11-21
<<U1>                 <datetime64[D]>
>>> ih.roll(2)
<IndexHierarchyGO: x>
c                     1517-04-01
c                     1620-11-21
a                     1517-04-01
a                     1620-11-21
b                     1517-04-01
b                     1620-11-21
<<U1>                 <datetime64[D]>
IndexHierarchyGO.sample(count=1, *, seed=None)

Randomly (optionally made deterministic with a fixed seed) extract items from the container to return a subset of the container.

Parameters
  • select. (Number of elements to) –

  • selection. (Initial state of random) –

>>> ih = sf.IndexHierarchyGO.from_product(('a', 'b', 'c'), ('1517-04-01', '1620-11-21'), name='x', index_constructors=(sf.Index, sf.IndexDate))
>>> ih
<IndexHierarchyGO: x>
a                     1517-04-01
a                     1620-11-21
b                     1517-04-01
b                     1620-11-21
c                     1517-04-01
c                     1620-11-21
<<U1>                 <datetime64[D]>
>>> ih.sample(2, seed=0)
<IndexHierarchyGO: x>
b                     1517-04-01
c                     1620-11-21
<<U1>                 <datetime64[D]>
IndexHierarchyGO.sort(*, ascending=True, kind='mergesort', key=None)

Return a new Index with the labels sorted.

Parameters
  • ascendings – Boolean, or iterable of Booleans; if True, the lowest ranks correspond to the lowest values; if an iterable, apply per column or row. The default is True.

  • kind – Name of the sort algorithm as passed to NumPy.

  • key – A function that is used to pre-process the selected columns or rows and derive new values to sort by.

>>> ih = sf.IndexHierarchyGO.from_labels((('b', 1024, True), ('a', 1024, True), ('a', 2048, True), ('a', 2048, False)), name='x')
>>> ih
<IndexHierarchyGO: x>
b                     1024    True
a                     1024    True
a                     2048    True
a                     2048    False
<<U1>                 <int64> <bool>
>>> ih.sort()
<IndexHierarchyGO: x>
a                     1024    True
a                     2048    False
a                     2048    True
b                     1024    True
<<U1>                 <int64> <bool>
>>> ih.sort(ascending=False)
<IndexHierarchyGO: x>
b                     1024    True
a                     2048    True
a                     2048    False
a                     1024    True
<<U1>                 <int64> <bool>
IndexHierarchyGO.std(axis=0, skipna=True, ddof=0, out=None)

Return the standard deviaton along the specified axis.

Parameters
  • axis – Axis, defaulting to axis 0.

  • skipna – Skip missing (NaN) values, defaulting to True.

>>> ih = sf.IndexHierarchyGO.from_labels(((0, 1024, 32), (1, -2048, 32), (1, 1024, 32)), name=('x', 'y', 'z'))
>>> ih.std()
NotImplementedError('functools.partial(<function std at 0x7fbdfe7fd280>, ddof=0) for IndexHierarchyGO is not defined; convert to `Frame`.')
IndexHierarchyGO.sum(axis=0, skipna=True, out=None)

Sum values along the specified axis.

Parameters
  • axis – Axis, defaulting to axis 0.

  • skipna – Skip missing (NaN) values, defaulting to True.

>>> ih = sf.IndexHierarchyGO.from_labels(((0, 1024, 32), (1, -2048, 32), (1, 1024, 32)), name=('x', 'y', 'z'))
>>> ih.sum()
NotImplementedError('<function sum at 0x7fbdfe7f5a60> for IndexHierarchyGO is not defined; convert to `Frame`.')
IndexHierarchyGO.tail(count=5)

Return a Index consisting only of the bottom elements as specified by count.

Parameters

count – Number of elements to be returned from the bottom of the Index

>>> ih = sf.IndexHierarchyGO.from_product(('a', 'b', 'c'), ('1517-04-01', '1620-11-21'), name='x', index_constructors=(sf.Index, sf.IndexDate))
>>> ih
<IndexHierarchyGO: x>
a                     1517-04-01
a                     1620-11-21
b                     1517-04-01
b                     1620-11-21
c                     1517-04-01
c                     1620-11-21
<<U1>                 <datetime64[D]>
>>> ih.tail(2)
<IndexHierarchyGO: x>
c                     1517-04-01
c                     1620-11-21
<<U1>                 <datetime64[D]>
IndexHierarchyGO.union(*others)

Perform union with another Index, container, or NumPy array. Identical comparisons retain order.

>>> ih1 = sf.IndexHierarchyGO.from_labels((('a', 1024, True), ('a', 2048, True), ('a', 2048, False)), name='x')
>>> ih2 = sf.IndexHierarchyGO.from_labels((('a', 1024, True), ('b', 1024, True)), name='y')
>>> ih1.union(ih2)
<IndexHierarchyGO>
a                  1024    True
a                  2048    False
a                  2048    True
b                  1024    True
<<U1>              <int64> <bool>
IndexHierarchyGO.unique(depth_level=0, order_by_occurrence=False)

Return a NumPy array of unique values.

Parameters
  • depth_level – Specify a single depth or multiple depths in an iterable.

  • order_by_occurrence – if True, values are ordered by when they first appear

Returns

numpy.ndarray

>>> ih = sf.IndexHierarchyGO.from_labels(((0, 1024), (1, 2048), (np.nan, np.nan)), name=('x', 'y'))
>>> ih
<IndexHierarchyGO: ('x', 'y')>
0.0                            1024.0
1.0                            2048.0
nan                            nan
<float64>                      <float64>
>>> ih.unique()
[ 0.  1. nan]
IndexHierarchyGO.values_at_depth(depth_level=0)

Return an NP array for the depth_level specified.

Parameters

depth_level – a single depth level, or iterable depth of depth levels.

>>> ih = sf.IndexHierarchyGO.from_labels((('a', 1024, '1517-04-01'), ('a', 2048, '1789-12-31'), ('b', 0, '1620-11-21')), index_constructors=(sf.Index, sf.Index, sf.IndexDate), name=('x', 'y', 'z'))
>>> ih.values_at_depth(0)
['a' 'a' 'b']
>>> ih.values_at_depth(2)
['1517-04-01' '1789-12-31' '1620-11-21']
IndexHierarchyGO.var(axis=0, skipna=True, ddof=0, out=None)

Return the variance along the specified axis.

Parameters
  • axis – Axis, defaulting to axis 0.

  • skipna – Skip missing (NaN) values, defaulting to True.

>>> ih = sf.IndexHierarchyGO.from_labels(((0, 1024, 32), (1, -2048, 32), (1, 1024, 32)), name=('x', 'y', 'z'))
>>> ih.var()
NotImplementedError('functools.partial(<function var at 0x7fbdfe7fd430>, ddof=0) for IndexHierarchyGO is not defined; convert to `Frame`.')

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