Detail: Yarn: Method

Overview: Yarn: Method

Yarn.__bool__()

Raises ValueError to prohibit ambiguous use of truthy evaluation.

>>> 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')
>>> 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')
>>> y = sf.Yarn.from_buses((b1, b2), retain_labels=False)
>>> bool(y)
ErrorNotTruthy('The truth value of a container is ambiguous. For a truthy indicator of non-empty status, use the `size` attribute.')
Yarn.__len__()[source]

Length of values.

>>> 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')
>>> 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')
>>> y = sf.Yarn.from_buses((b1, b2), retain_labels=False)
>>> len(y)
4
Yarn.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')
>>> 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')
>>> b3 = 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')
>>> y1 = sf.Yarn.from_buses((b1, b2), retain_labels=False)
>>> y1
<Yarn>
<Index>
x       Frame
y       Frame
v       Frame
w       Frame
<<U1>   <object>
>>> y2 = sf.Yarn.from_buses((b3,), retain_labels=False)
>>> y2
<Yarn>
<Index>
x       Frame
y       Frame
v       Frame
w       Frame
<<U1>   <object>
>>> y1.equals(y2)
True
Yarn.head(count=5)[source]

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

Parameters

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

Returns

Yarn

>>> 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')
>>> 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')
>>> y = sf.Yarn.from_buses((b1, b2), retain_labels=False)
>>> y.head(2)
<Yarn>
<Index>
x       Frame
y       Frame
<<U1>   <object>
Yarn.rehierarch(depth_map, *, index_constructors=None)[source]

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

>>> 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')
>>> 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')
>>> y = sf.Yarn.from_buses((b1, b2), retain_labels=True)
>>> y
<Yarn>
<IndexHierarchy>
i                x     Frame
i                y     Frame
j                v     Frame
j                w     Frame
<<U1>            <<U1> <object>
>>> y.rehierarch((1, 0))
<Yarn>
<IndexHierarchy>
x                i     Frame
y                i     Frame
v                j     Frame
w                j     Frame
<<U1>            <<U1> <object>
Yarn.relabel(index)[source]

Return a new Yarn 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 a new Index 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. Previous 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 an auto-incremented integer index. (d) An index initializer, i.e., either an iterable of hashables or an Index instance.

>>> 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')
>>> 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')
>>> y = sf.Yarn.from_buses((b1, b2), retain_labels=True)
>>> y
<Yarn>
<IndexHierarchy>
i                x     Frame
i                y     Frame
j                v     Frame
j                w     Frame
<<U1>            <<U1> <object>
>>> y.relabel(('A', 'B', 'C', 'D'))
<Yarn>
<Index>
A       Frame
B       Frame
C       Frame
D       Frame
<<U1>   <object>
>>> y.relabel({('j', 'v'):('A', 'x')})
<Yarn>
<IndexHierarchy>
i                x     Frame
i                y     Frame
A                x     Frame
j                w     Frame
<<U1>            <<U1> <object>
Yarn.relabel_flat()[source]

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

>>> 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')
>>> 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')
>>> y = sf.Yarn.from_buses((b1, b2), retain_labels=True)
>>> y
<Yarn>
<IndexHierarchy>
i                x     Frame
i                y     Frame
j                v     Frame
j                w     Frame
<<U1>            <<U1> <object>
>>> y.relabel_flat()
<Yarn>
<Index>
('i', 'x') Frame
('i', 'y') Frame
('j', 'v') Frame
('j', 'w') Frame
<object>   <object>
Yarn.relabel_level_add(level)[source]

Return a new Yarn, 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

>>> 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')
>>> 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')
>>> y = sf.Yarn.from_buses((b1, b2), retain_labels=True)
>>> y
<Yarn>
<IndexHierarchy>
i                x     Frame
i                y     Frame
j                v     Frame
j                w     Frame
<<U1>            <<U1> <object>
>>> y.relabel_level_add('A')
<Yarn>
<IndexHierarchy>
A                i     x     Frame
A                i     y     Frame
A                j     v     Frame
A                j     w     Frame
<<U1>            <<U1> <<U1> <object>
Yarn.relabel_level_drop(count=1)[source]

Return a new Yarn, 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.

>>> 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')
>>> 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')
>>> y = sf.Yarn.from_buses((b1, b2), retain_labels=True)
>>> y
<Yarn>
<IndexHierarchy>
i                x     Frame
i                y     Frame
j                v     Frame
j                w     Frame
<<U1>            <<U1> <object>
>>> y.relabel_level_drop()
<Yarn>
<Index>
x       Frame
y       Frame
v       Frame
w       Frame
<<U1>   <object>
Yarn.rename(name)[source]

Return a new Yarn with an updated name attribute.

Parameters

name

>>> 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')
>>> 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')
>>> y = sf.Yarn.from_buses((b1, b2), retain_labels=True)
>>> y.rename('j')
<Yarn: j>
<IndexHierarchy>
i                x     Frame
i                y     Frame
j                v     Frame
j                w     Frame
<<U1>            <<U1> <object>
Yarn.tail(count=5)[source]
Return a Yarn consisting only of the bottom elements as specified by count.

s

Parameters

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

Returns

Yarn

>>> 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')
>>> 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')
>>> y = sf.Yarn.from_buses((b1, b2), retain_labels=False)
>>> y.tail(2)
<Yarn>
<Index>
v       Frame
w       Frame
<<U1>   <object>
Yarn.unpersist()[source]

For the Bus contained in this object, 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.to_zip_npz('/tmp/b1.zip')
>>> 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.to_zip_npz('/tmp/b2.zip')
>>> b1 = sf.Bus.from_zip_npz('/tmp/b1.zip').rename('a')
>>> b1
<Bus: a>
<Index>
x        <FrameDeferred>
y        <FrameDeferred>
<<U1>    <object>
>>> b2 = sf.Bus.from_zip_npz('/tmp/b2.zip').rename('b')
>>> b2
<Bus: b>
<Index>
v        <FrameDeferred>
w        <FrameDeferred>
<<U1>    <object>
>>> y = sf.Yarn.from_buses((b1, b2), retain_labels=False)
>>> tuple(y.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>, <Frame: v>
<Index>    a       b       <<U1>
<Index>
p          40      41
q          42      43
r          44      45
<<U1>      <int64> <int64>, <Frame: w>
<Index>    c      d      <<U1>
<Index>
p          False  True
q          True   False
r          True   True
<<U1>      <bool> <bool>)
>>> y
<Yarn>
<Index>
x       Frame
y       Frame
v       Frame
w       Frame
<<U1>   <object>
>>> y.unpersist()
>>> y
<Yarn>
<Index>
x       <FrameDeferred>
y       <FrameDeferred>
v       <FrameDeferred>
w       <FrameDeferred>
<<U1>   <object>

Yarn: Constructor | Exporter | Attribute | Method | Dictionary-Like | Display | Selector | Iterator | Accessor Hashlib