Detail: Bus: Method

Overview: Bus: Method

Bus.__bool__()

Raises ValueError to prohibit ambiguous use of truthy evaluation.

>>> b = sf.Bus.from_frames((sf.Frame(np.arange(6).reshape(3,2), index=('p', 'q', 'r'), columns=('a', 'b'), name='x'), sf.Frame((np.arange(6).reshape(3,2) % 2).astype(bool), index=('p', 'q', 'r'), columns=('c', 'd'), name='y')), name='i')
>>> b
<Bus: i>
<Index>
x        Frame
y        Frame
<<U1>    <object>
>>> bool(b)
ErrorNotTruthy('The truth value of a container is ambiguous. For a truthy indicator of non-empty status, use the `size` attribute.')
Bus.__len__()[source]

Length of values.

>>> b = sf.Bus.from_frames((sf.Frame(np.arange(6).reshape(3,2), index=('p', 'q', 'r'), columns=('a', 'b'), name='x'), sf.Frame((np.arange(6).reshape(3,2) % 2).astype(bool), index=('p', 'q', 'r'), columns=('c', 'd'), name='y')), name='i')
>>> b
<Bus: i>
<Index>
x        Frame
y        Frame
<<U1>    <object>
>>> len(b)
2
Bus.equals(other, *, compare_name=False, compare_dtype=False, compare_class=False, skipna=True)[source]

Return a bool from comparison to any other object.

Note: this will attempt to load and compare all Frame managed by the Bus.

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.

>>> b1 = sf.Bus.from_frames((sf.Frame(np.arange(6).reshape(3,2), index=('p', 'q', 'r'), columns=('a', 'b'), name='x'), sf.Frame((np.arange(6).reshape(3,2) % 2).astype(bool), index=('p', 'q', 'r'), columns=('c', 'd'), name='y')), name='i')
>>> b1
<Bus: i>
<Index>
x        Frame
y        Frame
<<U1>    <object>
>>> b2 = sf.Bus.from_frames((sf.Frame(np.arange(40, 46).reshape(3,2), index=('p', 'q', 'r'), columns=('a', 'b'), name='v'), sf.Frame((np.arange(6).reshape(3,2) % 3).astype(bool), index=('p', 'q', 'r'), columns=('c', 'd'), name='w')), name='j')
>>> b2
<Bus: j>
<Index>
v        Frame
w        Frame
<<U1>    <object>
>>> b1.equals(b2)
False
Bus.head(count=5)[source]

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

Parameters:

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

Returns:

Bus

>>> b = sf.Bus.from_frames((sf.Frame(np.arange(6).reshape(3,2), index=('p', 'q', 'r'), columns=('a', 'b'), name='x'), sf.Frame((np.arange(6).reshape(3,2) % 2).astype(bool), index=('p', 'q', 'r'), columns=('c', 'd'), name='y'), sf.Frame(np.arange(40, 46).reshape(3,2), index=('p', 'q', 'r'), columns=('a', 'b'), name='v'), sf.Frame((np.arange(6).reshape(3,2) % 3).astype(bool), index=('p', 'q', 'r'), columns=('c', 'd'), name='w')), name='k')
>>> b
<Bus: k>
<Index>
x        Frame
y        Frame
v        Frame
w        Frame
<<U1>    <object>
>>> b.head(2)
<Bus: k>
<Index>
x        Frame
y        Frame
<<U1>    <object>
Bus.rehierarch(depth_map, *, index_constructors=None)[source]

Return a new Bus with new a hierarchy based on the supplied depth_map.

>>> b = sf.Bus.from_items(((('i', 1024), sf.Frame(np.arange(6).reshape(3,2), index=('p', 'q', 'r'), columns=('a', 'b'), name='x')), (('j', 4096), sf.Frame((np.arange(6).reshape(3,2) % 2).astype(bool), index=('p', 'q', 'r'), columns=('c', 'd'), name='y')), (('j', 2048), sf.Frame(np.arange(6).reshape(3,2), index=('p', 'q', 'r'), columns=('a', 'b'), name='x'))), index_constructor=sf.IndexHierarchy.from_labels)
>>> b
<Bus>
<IndexHierarchy>
i                1024    Frame
j                4096    Frame
j                2048    Frame
<<U1>            <int64> <object>
>>> b.rehierarch((1, 0))
<Bus>
<IndexHierarchy>
1024             i     Frame
4096             j     Frame
2048             j     Frame
<int64>          <<U1> <object>
Bus.reindex(index, *, fill_value, own_index=False, check_equals=True)[source]

Return a new Bus with labels defined by the provided index. The size and ordering of the data is determined by the newly provided index, where data will continue to be aligned under labels found in both the new and the old index. Labels found only in the new index will be filled with fill_value.

Parameters:
  • index – An iterable of unique, hashable values, or another Index or IndexHierarchy, to be used as the labels of the index.

  • columns – An iterable of unique, hashable values, or another Index or IndexHierarchy, to be used as the labels of the index.

  • fill_value – A value to be used to fill space created by a new index that has values not found in the previous index.

  • own_index – Flag the passed index as ownable by this static_frame.Bus. Primarily used by internal clients.

>>> b = sf.Bus.from_frames((sf.Frame(np.arange(6).reshape(3,2), index=('p', 'q', 'r'), columns=('a', 'b'), name='x'), sf.Frame((np.arange(6).reshape(3,2) % 2).astype(bool), index=('p', 'q', 'r'), columns=('c', 'd'), name='y')), name='i')
>>> b
<Bus: i>
<Index>
x        Frame
y        Frame
<<U1>    <object>
>>> b.reindex(('y', 'z'), fill_value=sf.Frame()).status
<Frame>
<Index> loaded size      nbytes    shape    <<U6>
<Index>
y       True   6.0       6.0       (3, 2)
z       True   0.0       0.0       (0, 0)
<<U1>   <bool> <float64> <float64> <object>
Bus.relabel(index, *, index_constructor=None)[source]

Return a new Bus with transformed labels on the index. The size and ordering of the data is never changed in a relabeling operation. The resulting index must be unique.

Parameters:

index – One of the following types, used to create new index labels with the same size as the previous index. (a) A mapping (as a dictionary or Series), used to lookup and transform the labels in the previous index. Labels not found in the mapping will be reused. (b) A function, returning a hashable, that is applied to each label in the previous index. (c) The IndexAutoFactory type, to apply auto-incremented integer labels. (d) An Index initializer, i.e., either an iterable of hashables or an Index instance.

>>> b = sf.Bus.from_frames((sf.Frame(np.arange(6).reshape(3,2), index=('p', 'q', 'r'), columns=('a', 'b'), name='x'), sf.Frame((np.arange(6).reshape(3,2) % 2).astype(bool), index=('p', 'q', 'r'), columns=('c', 'd'), name='y')), name='i')
>>> b
<Bus: i>
<Index>
x        Frame
y        Frame
<<U1>    <object>
>>> b.relabel(('A', 'B'))
<Bus: i>
<Index>
A        Frame
B        Frame
<<U1>    <object>
>>> b.relabel(dict(x='A'))
<Bus: i>
<Index>
A        Frame
y        Frame
<<U1>    <object>
>>> b.relabel(lambda l: f'+{l.upper()}+')
<Bus: i>
<Index>
+X+      Frame
+Y+      Frame
<<U3>    <object>
Bus.relabel_flat()[source]

Return a new Bus, where an IndexHierarchy (if defined) is replaced with a flat, one-dimension index of tuples.

>>> b = sf.Bus.from_items(((('i', 1024), sf.Frame(np.arange(6).reshape(3,2), index=('p', 'q', 'r'), columns=('a', 'b'), name='x')), (('j', 4096), sf.Frame((np.arange(6).reshape(3,2) % 2).astype(bool), index=('p', 'q', 'r'), columns=('c', 'd'), name='y')), (('j', 2048), sf.Frame(np.arange(6).reshape(3,2), index=('p', 'q', 'r'), columns=('a', 'b'), name='x'))), index_constructor=sf.IndexHierarchy.from_labels)
>>> b
<Bus>
<IndexHierarchy>
i                1024    Frame
j                4096    Frame
j                2048    Frame
<<U1>            <int64> <object>
>>> b.relabel_flat()
<Bus>
<Index>
('i', 1024) Frame
('j', 4096) Frame
('j', 2048) Frame
<object>    <object>
Bus.relabel_level_add(level)[source]

Return a new Bus, adding a new root level to an existing IndexHierarchy, or creating an IndexHierarchy if one is not yet defined.

Parameters:

level – A hashable value to be used as a new root level, extending or creating an IndexHierarchy

>>> b = sf.Bus.from_frames((sf.Frame(np.arange(6).reshape(3,2), index=('p', 'q', 'r'), columns=('a', 'b'), name='x'), sf.Frame((np.arange(6).reshape(3,2) % 2).astype(bool), index=('p', 'q', 'r'), columns=('c', 'd'), name='y')), name='i')
>>> b
<Bus: i>
<Index>
x        Frame
y        Frame
<<U1>    <object>
>>> b.relabel_level_add(2048)
<Bus: i>
<IndexHierarchy>
2048             x     Frame
2048             y     Frame
<int64>          <<U1> <object>
Bus.relabel_level_drop(count=1)[source]

Return a new Bus, dropping one or more levels from a either the root or the leaves of an IndexHierarchy. The resulting index must be unique.

Parameters:

count – A positive integer drops that many outer-most (root) levels; a negative integer drops that many inner-most (leaf)levels.

>>> b = sf.Bus.from_items(((('i', 1024), sf.Frame(np.arange(6).reshape(3,2), index=('p', 'q', 'r'), columns=('a', 'b'), name='x')), (('j', 4096), sf.Frame((np.arange(6).reshape(3,2) % 2).astype(bool), index=('p', 'q', 'r'), columns=('c', 'd'), name='y')), (('j', 2048), sf.Frame(np.arange(6).reshape(3,2), index=('p', 'q', 'r'), columns=('a', 'b'), name='x'))), index_constructor=sf.IndexHierarchy.from_labels)
>>> b
<Bus>
<IndexHierarchy>
i                1024    Frame
j                4096    Frame
j                2048    Frame
<<U1>            <int64> <object>
>>> b.relabel_level_drop()
<Bus>
<Index>
1024    Frame
4096    Frame
2048    Frame
<int64> <object>
Bus.rename(name)[source]

Return a new Bus with an updated name attribute.

>>> b = sf.Bus.from_frames((sf.Frame(np.arange(6).reshape(3,2), index=('p', 'q', 'r'), columns=('a', 'b'), name='x'), sf.Frame((np.arange(6).reshape(3,2) % 2).astype(bool), index=('p', 'q', 'r'), columns=('c', 'd'), name='y')), name='i')
>>> b
<Bus: i>
<Index>
x        Frame
y        Frame
<<U1>    <object>
>>> b.rename('j')
<Bus: j>
<Index>
x        Frame
y        Frame
<<U1>    <object>
Bus.roll(shift, *, include_index=False)[source]

Return a Bus with values rotated forward and wrapped around the index (with a positive shift) or backward and wrapped around the index (with a negative shift).

Parameters:
  • shift – Positive or negative integer shift.

  • include_index – Determine if the Index is shifted with the underlying data.

Returns:

Bus

>>> b = sf.Bus.from_frames((sf.Frame(np.arange(6).reshape(3,2), index=('p', 'q', 'r'), columns=('a', 'b'), name='x'), sf.Frame((np.arange(6).reshape(3,2) % 2).astype(bool), index=('p', 'q', 'r'), columns=('c', 'd'), name='y'), sf.Frame(np.arange(40, 46).reshape(3,2), index=('p', 'q', 'r'), columns=('a', 'b'), name='v'), sf.Frame((np.arange(6).reshape(3,2) % 3).astype(bool), index=('p', 'q', 'r'), columns=('c', 'd'), name='w')), name='k')
>>> b
<Bus: k>
<Index>
x        Frame
y        Frame
v        Frame
w        Frame
<<U1>    <object>
>>> b.roll(2)
<Bus: k>
<Index>
x        Frame
y        Frame
v        Frame
w        Frame
<<U1>    <object>
Bus.shift(shift, *, fill_value)[source]

Return a Bus with values shifted forward on the index (with a positive shift) or backward on the index (with a negative shift).

Parameters:
  • shift – Positive or negative integer shift.

  • fill_value – Value to be used to fill data missing after the shift.

Returns:

Bus

>>> b = sf.Bus.from_frames((sf.Frame(np.arange(6).reshape(3,2), index=('p', 'q', 'r'), columns=('a', 'b'), name='x'), sf.Frame((np.arange(6).reshape(3,2) % 2).astype(bool), index=('p', 'q', 'r'), columns=('c', 'd'), name='y'), sf.Frame(np.arange(40, 46).reshape(3,2), index=('p', 'q', 'r'), columns=('a', 'b'), name='v'), sf.Frame((np.arange(6).reshape(3,2) % 3).astype(bool), index=('p', 'q', 'r'), columns=('c', 'd'), name='w')), name='k')
>>> b
<Bus: k>
<Index>
x        Frame
y        Frame
v        Frame
w        Frame
<<U1>    <object>
>>> b.shift(2, fill_value=sf.Frame()).status
<Frame>
<Index> loaded size      nbytes    shape    <<U6>
<Index>
x       True   0.0       0.0       (0, 0)
y       True   0.0       0.0       (0, 0)
v       True   6.0       48.0      (3, 2)
w       True   6.0       6.0       (3, 2)
<<U1>   <bool> <float64> <float64> <object>
Bus.sort_index(*, ascending=True, kind='mergesort', key=None)[source]

Return a new Bus ordered by the sorted Index.

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.

Returns:

Bus

>>> b = sf.Bus.from_frames((sf.Frame(np.arange(6).reshape(3,2), index=('p', 'q', 'r'), columns=('a', 'b'), name='x'), sf.Frame((np.arange(6).reshape(3,2) % 2).astype(bool), index=('p', 'q', 'r'), columns=('c', 'd'), name='y'), sf.Frame(np.arange(40, 46).reshape(3,2), index=('p', 'q', 'r'), columns=('a', 'b'), name='v'), sf.Frame((np.arange(6).reshape(3,2) % 3).astype(bool), index=('p', 'q', 'r'), columns=('c', 'd'), name='w')), name='k')
>>> b
<Bus: k>
<Index>
x        Frame
y        Frame
v        Frame
w        Frame
<<U1>    <object>
>>> b.sort_index()
<Bus: k>
<Index>
v        Frame
w        Frame
x        Frame
y        Frame
<<U1>    <object>
>>> b.sort_index(ascending=False)
<Bus: k>
<Index>
y        Frame
x        Frame
w        Frame
v        Frame
<<U1>    <object>
Bus.sort_values(*, ascending=True, kind='mergesort', key)[source]

Return a new Bus ordered by the sorted values. Note that as a Bus contains Frames, a key argument must be provided to extract a sortable value, and this key function will process a Series of Frame.

Parameters:
  • *

  • ascending – If True, sort in ascending order; if False, sort in descending order.

  • 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.

Returns:

Bus

>>> b = sf.Bus.from_frames((sf.Frame(np.arange(6).reshape(3,2), index=('p', 'q', 'r'), columns=('a', 'b'), name='x'), sf.Frame((np.arange(6).reshape(3,2) % 2).astype(bool), index=('p', 'q', 'r'), columns=('c', 'd'), name='y'), sf.Frame(np.arange(40, 46).reshape(3,2), index=('p', 'q', 'r'), columns=('a', 'b'), name='v'), sf.Frame((np.arange(6).reshape(3,2) % 3).astype(bool), index=('p', 'q', 'r'), columns=('c', 'd'), name='w')), name='k')
>>> b
<Bus: k>
<Index>
x        Frame
y        Frame
v        Frame
w        Frame
<<U1>    <object>
>>> b.sort_values(key=lambda s:s.iter_element().apply(lambda f: f.nbytes))
<Bus: k>
<Index>
y        Frame
w        Frame
x        Frame
v        Frame
<<U1>    <object>
>>> b.sort_values(key=lambda s:s.iter_element().apply(lambda f: f.nbytes), ascending=False)
<Bus: k>
<Index>
v        Frame
x        Frame
w        Frame
y        Frame
<<U1>    <object>
Bus.tail(count=5)[source]
Return a Bus consisting only of the bottom elements as specified by count.

s

Parameters:

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

Returns:

Bus

>>> b = sf.Bus.from_frames((sf.Frame(np.arange(6).reshape(3,2), index=('p', 'q', 'r'), columns=('a', 'b'), name='x'), sf.Frame((np.arange(6).reshape(3,2) % 2).astype(bool), index=('p', 'q', 'r'), columns=('c', 'd'), name='y'), sf.Frame(np.arange(40, 46).reshape(3,2), index=('p', 'q', 'r'), columns=('a', 'b'), name='v'), sf.Frame((np.arange(6).reshape(3,2) % 3).astype(bool), index=('p', 'q', 'r'), columns=('c', 'd'), name='w')), name='k')
>>> b
<Bus: k>
<Index>
x        Frame
y        Frame
v        Frame
w        Frame
<<U1>    <object>
>>> b.tail(2)
<Bus: k>
<Index>
v        Frame
w        Frame
<<U1>    <object>
Bus.unpersist()[source]

Replace all loaded Frame with FrameDeferred.

>>> b1 = sf.Bus.from_frames((sf.Frame(np.arange(6).reshape(3,2), index=('p', 'q', 'r'), columns=('a', 'b'), name='x'), sf.Frame((np.arange(6).reshape(3,2) % 2).astype(bool), index=('p', 'q', 'r'), columns=('c', 'd'), name='y')), name='i')
>>> b1
<Bus: i>
<Index>
x        Frame
y        Frame
<<U1>    <object>
>>> b1.to_zip_npz('/tmp/b.zip')
>>> b2 = sf.Bus.from_zip_npz('/tmp/b.zip')
>>> b2
<Bus>
<Index>
x       <FrameDeferred>
y       <FrameDeferred>
<<U1>   <object>
>>> tuple(b2.values)
(<Frame: x>
<Index>    a       b       <<U1>
<Index>
p          0       1
q          2       3
r          4       5
<<U1>      <int64> <int64>, <Frame: y>
<Index>    c      d      <<U1>
<Index>
p          False  True
q          False  True
r          False  True
<<U1>      <bool> <bool>)
>>> b2
<Bus>
<Index>
x       Frame
y       Frame
<<U1>   <object>
>>> b2.unpersist()
>>> b2
<Bus>
<Index>
x       <FrameDeferred>
y       <FrameDeferred>
<<U1>   <object>

Bus: Constructor | Exporter | Attribute | Method | Dictionary-Like | Display | Selector | Iterator | Accessor Hashlib | Accessor Type Clinic