Detail: 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) >>> y <Yarn> <Index> x Frame y Frame v Frame w Frame <<U1> <object> >>> 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) >>> y <Yarn> <Index> x Frame y Frame v Frame w Frame <<U1> <object> >>> 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 bycount
.>>> 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 <Yarn> <Index> x Frame y Frame v Frame w Frame <<U1> <object> >>> 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 supplieddepth_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.reindex(index, *, fill_value=None, 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 withfill_value
.- Parameters:
index – An iterable of unique, hashable values, or another
Index
orIndexHierarchy
, to be used as the labels of the index.columns – An iterable of unique, hashable values, or another
Index
orIndexHierarchy
, 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.
>>> y1 = sf.Yarn.from_buses((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'), 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')), retain_labels=False) >>> y1 <Yarn> <Index> x Frame y Frame v Frame w Frame <<U1> <object> >>> y1.reindex(('y', 'x', 'v')) <Yarn> <Index> y Frame x Frame v Frame <<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 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) TheIndexAutoFactory
type, to apply auto-incremented integer labels. (d) AnIndex
initializer, i.e., either an iterable of hashables or anIndex
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 anIndexHierarchy
(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 existingIndexHierarchy
, or creating anIndexHierarchy
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 anIndexHierarchy
. 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 <Yarn> <IndexHierarchy> i x Frame i y Frame j v Frame j w Frame <<U1> <<U1> <object> >>> y.rename('j') <Yarn: j> <IndexHierarchy> i x Frame i y Frame j v Frame j w Frame <<U1> <<U1> <object>
- Yarn.roll(shift, *, include_index=False)[source]
Return a Yarn 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:
>>> y1 = sf.Yarn.from_buses((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'), 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')), retain_labels=False) >>> y1 <Yarn> <Index> x Frame y Frame v Frame w Frame <<U1> <object> >>> y1.roll(1) <Yarn> <Index> x Frame y Frame v Frame w Frame <<U1> <object> >>> y1.roll(1, include_index=True) <Yarn> <Index> w Frame x Frame y Frame v Frame <<U1> <object>
- Yarn.shift(shift, *, fill_value)[source]
Return a
Yarn
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:
>>> y1 = sf.Yarn.from_buses((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'), 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')), retain_labels=False) >>> y1 <Yarn> <Index> x Frame y Frame v Frame w Frame <<U1> <object> >>> y1.shift(1, fill_value=None) NotImplementedError('A `Yarn` cannot be shifted as newly created missing values cannot be filled without replacing stored `Bus`.')
- Yarn.sort_index(*, ascending=True, kind='mergesort', key=None)[source]
Return a new Yarn 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 isTrue
.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:
>>> y1 = sf.Yarn.from_buses((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'), 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')), retain_labels=False) >>> y1 <Yarn> <Index> x Frame y Frame v Frame w Frame <<U1> <object> >>> y2 = y1.sort_index() >>> y2 <Yarn> <Index> v Frame w Frame x Frame y Frame <<U1> <object>
- Yarn.sort_values(*, ascending=True, kind='mergesort', key)[source]
Return a new Yarn ordered by the sorted values. Note that as a Yarn contains Frames, a key argument must be provided to extract a sortable value, and this key function will process a
Series
ofFrame
.- 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:
>>> y1 = sf.Yarn.from_buses((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'), 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')), retain_labels=False) >>> y1 <Yarn> <Index> x Frame y Frame v Frame w Frame <<U1> <object> >>> y1.sort_values(key=lambda y: np.array([f.size for f in y.iter_element()])) <Yarn> <Index> x Frame y Frame v Frame w Frame <<U1> <object>
- Yarn.tail(count=5)[source]
- Return a
Yarn
consisting only of the bottom elements as specified bycount
. s
>>> 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 <Yarn> <Index> x Frame y Frame v Frame w Frame <<U1> <object> >>> y.tail(2) <Yarn> <Index> v Frame w Frame <<U1> <object>
- Return a
- Yarn.unpersist()[source]
For the
Bus
contained in this object, replace all loadedFrame
withFrameDeferred
.>>> 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) >>> y <Yarn> <Index> x <FrameDeferred> y <FrameDeferred> v <FrameDeferred> w <FrameDeferred> <<U1> <object> >>> 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 | Accessor Type Clinic