towhee.functional.mixins.stream.StreamMixin¶
- class towhee.functional.mixins.stream.StreamMixin[source]¶
Bases:
object
Stream related mixins.
Methods
Create a stream data collection.
Create a unstream data collection.
Attributes
Check whether the data collection is stream or unstream.
- property is_stream¶
Check whether the data collection is stream or unstream.
Examples:
>>> from towhee import DataCollection >>> from typing import Iterable >>> dc = DataCollection([0,1,2,3,4]) >>> dc.is_stream False
>>> result = dc.map(lambda x: x+1) >>> result.is_stream False >>> result._iterable [1, 2, 3, 4, 5]
>>> dc = DataCollection(iter(range(5))) >>> dc.is_stream True
>>> result = dc.map(lambda x: x+1) >>> result.is_stream True >>> isinstance(result._iterable, Iterable) True
- stream()[source]¶
Create a stream data collection.
Examples: 1. Convert a data collection to streamed version
>>> from towhee import DataCollection >>> dc = DataCollection([0, 1, 2, 3, 4]) >>> dc.is_stream False
>>> dc = dc.stream() >>> dc.is_stream True
- unstream()[source]¶
Create a unstream data collection.
Examples:
Create a unstream data collection
>>> from towhee import DataCollection >>> dc = DataCollection(iter(range(5))).unstream() >>> dc.is_stream False
Convert a streamed data collection to unstream version
>>> dc = DataCollection(iter(range(5))) >>> dc.is_stream True >>> dc = dc.unstream() >>> dc.is_stream False