Detail: Bus: Iterator
- Bus.iter_element
- iter_element
Iterator of elements.
>>> 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> >>> tuple(b.iter_element()) (<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>)
- Bus.iter_element().apply(func, *, dtype, name, index_constructor, columns_constructor)
- iter_element
Iterator of elements.
- IterNodeDelegate.apply(func, *, dtype=None, name=None, index_constructor=None, columns_constructor=None)[source]
Apply a function to each value. Returns a new container.
- Parameters:
func – A function that takes a value.
dtype – A value suitable for specyfying a NumPy dtype, such as a Python type (float), NumPy array protocol strings (‘f8’), or a dtype 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'), 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.iter_element().apply(lambda f: f.shape) <Series> <Index> x (3, 2) y (3, 2) v (3, 2) w (3, 2) <<U1> <object>
- Bus.iter_element().apply_iter(func)
- iter_element
Iterator of elements.
- IterNodeDelegate.apply_iter(func)[source]
Apply a function to each value. A generator of resulting values.
- Parameters:
func – A function that takes a value.
- Yields:
Values after function application.
>>> 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> >>> tuple(b.iter_element().apply_iter(lambda f: f.nbytes)) (48, 6, 48, 6)
- Bus.iter_element().apply_iter_items(func)
- iter_element
Iterator of elements.
- IterNodeDelegate.apply_iter_items(func)[source]
Apply a function to each value. A generator of resulting key, value pairs.
- Parameters:
func – A function that takes a value.
- Yields:
Pairs of label, value after function application.
>>> 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> >>> tuple(b.iter_element().apply_iter_items(lambda f: f.nbytes)) (('x', 48), ('y', 6), ('v', 48), ('w', 6))
- Bus.iter_element().apply_pool(func, *, dtype, name, index_constructor, max_workers, chunksize, use_threads)
- iter_element
Iterator of elements.
- IterNodeDelegate.apply_pool(func, *, dtype=None, name=None, index_constructor=None, max_workers=None, chunksize=1, use_threads=False)[source]
Apply a function to each value. Employ parallel processing with either the ProcessPoolExecutor or ThreadPoolExecutor.
- Parameters:
func – A function that takes a value.
* –
dtype – A value suitable for specyfying a NumPy dtype, such as a Python type (float), NumPy array protocol strings (‘f8’), or a dtype instance.
name – A hashable object to label the container.
max_workers – Number of parallel executors, as passed to the Thread- or ProcessPoolExecutor;
None
defaults to the max number of machine processes.chunksize – Units of work per executor, as passed to the Thread- or ProcessPoolExecutor.
use_threads – Use the ThreadPoolExecutor instead of the ProcessPoolExecutor.
>>> 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> >>> def func(f): return f.sum().sum() >>> b.iter_element().apply_pool(func, use_threads=True) <Series> <Index> x 15 y 3 v 255 w 4 <<U1> <int64>
- Bus.iter_element_items
- iter_element_items
Iterator of label, element pairs.
>>> 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> >>> tuple(b.iter_element_items()) (('x', <Frame: x> <Index> a b <<U1> <Index> p 0 1 q 2 3 r 4 5 <<U1> <int64> <int64>), ('y', <Frame: y> <Index> c d <<U1> <Index> p False True q False True r False True <<U1> <bool> <bool>), ('v', <Frame: v> <Index> a b <<U1> <Index> p 40 41 q 42 43 r 44 45 <<U1> <int64> <int64>), ('w', <Frame: w> <Index> c d <<U1> <Index> p False True q True False r True True <<U1> <bool> <bool>))
- Bus.iter_element_items().apply(func, *, dtype, name, index_constructor, columns_constructor)
- iter_element_items
Iterator of label, element pairs.
- IterNodeDelegate.apply(func, *, dtype=None, name=None, index_constructor=None, columns_constructor=None)[source]
Apply a function to each value. Returns a new container.
- Parameters:
func – A function that takes a value.
dtype – A value suitable for specyfying a NumPy dtype, such as a Python type (float), NumPy array protocol strings (‘f8’), or a dtype 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'), 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.iter_element_items().apply(lambda l, f: f.size if l != 'v' else 0) <Series> <Index> x 6 y 6 v 0 w 6 <<U1> <int64>
- Bus.iter_element_items().apply_iter(func)
- iter_element_items
Iterator of label, element pairs.
- IterNodeDelegate.apply_iter(func)[source]
Apply a function to each value. A generator of resulting values.
- Parameters:
func – A function that takes a value.
- Yields:
Values after function application.
>>> 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> >>> tuple(b.iter_element_items().apply_iter(lambda l, f: f.shape if l != 'x' else 0)) (0, (3, 2), (3, 2), (3, 2))
- Bus.iter_element_items().apply_iter_items(func)
- iter_element_items
Iterator of label, element pairs.
- IterNodeDelegate.apply_iter_items(func)[source]
Apply a function to each value. A generator of resulting key, value pairs.
- Parameters:
func – A function that takes a value.
- Yields:
Pairs of label, value after function application.
>>> 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> >>> tuple(b.iter_element_items().apply_iter_items(lambda l, f: f.shape if l != 'x' else 0)) (('x', 0), ('y', (3, 2)), ('v', (3, 2)), ('w', (3, 2)))
- Bus.iter_element_items().apply_pool(func, *, dtype, name, index_constructor, max_workers, chunksize, use_threads)
- iter_element_items
Iterator of label, element pairs.
- IterNodeDelegate.apply_pool(func, *, dtype=None, name=None, index_constructor=None, max_workers=None, chunksize=1, use_threads=False)[source]
Apply a function to each value. Employ parallel processing with either the ProcessPoolExecutor or ThreadPoolExecutor.
- Parameters:
func – A function that takes a value.
* –
dtype – A value suitable for specyfying a NumPy dtype, such as a Python type (float), NumPy array protocol strings (‘f8’), or a dtype instance.
name – A hashable object to label the container.
max_workers – Number of parallel executors, as passed to the Thread- or ProcessPoolExecutor;
None
defaults to the max number of machine processes.chunksize – Units of work per executor, as passed to the Thread- or ProcessPoolExecutor.
use_threads – Use the ThreadPoolExecutor instead of the ProcessPoolExecutor.
>>> 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> >>> def func(pair): return pair[1].sum().sum() if pair[0] != 'v' else -1 >>> b.iter_element_items().apply_pool(func, use_threads=True) <Series> <Index> x 15 y 3 v -1 w 4 <<U1> <int64>
Bus: Constructor | Exporter | Attribute | Method | Dictionary-Like | Display | Selector | Iterator | Accessor Hashlib | Accessor Type Clinic