reduce_processing_operator¶
Module that defines the ReduceProcessingOperator class
-
class
tasrif.processing_pipeline.reduce_processing_operator.
ReduceProcessingOperator
(observers=None)¶ The ReduceProcessingOperator is a specialized ProcessingOperator, where a reduce function is applied on each element of a list of inputs. Users can inherit from this operator to quickly build their own custom operators that perform reduce-like operations.
-
initial
(Any)¶ The initial element passed to the reduce function.
Examples
>>> import pandas as pd >>> from tasrif.processing_pipeline.reduce_processing_operator import ReduceProcessingOperator >>> >>> df0 = pd.DataFrame([[1, "2020-05-01 00:00:00", 1], [1, "2020-05-01 01:00:00", 1], >>> [1, "2020-05-01 03:00:00", 2], [2, "2020-05-02 00:00:00", 1], >>> [2, "2020-05-02 01:00:00", 1]], >>> columns=['logId', 'timestamp', 'sleep_level']) >>> >>> df1 = pd.DataFrame([['tom', 10], >>> ['Alfred', 15], >>> ['Alfred', 18], >>> ['juli', 14]], >>> columns=['name', 'age']) >>> >>> class AppendOperator(ReduceProcessingOperator): >>> initial = pd.DataFrame([["Harry", "2020-05-01 00:00:00"]], >>> columns=["name", "timestamp"]) >>> >>> def _processing_function(self, df_to_append, dfs): >>> return dfs.append(df_to_append) >>> >>> AppendOperator().process(df0, df1) name timestamp logId sleep_level age 0 Harry 2020-05-01 00:00:00 NaN NaN NaN 0 NaN 2020-05-01 00:00:00 1.0 1.0 NaN 1 NaN 2020-05-01 01:00:00 1.0 1.0 NaN 2 NaN 2020-05-01 03:00:00 1.0 2.0 NaN 3 NaN 2020-05-02 00:00:00 2.0 1.0 NaN 4 NaN 2020-05-02 01:00:00 2.0 1.0 NaN 0 tom NaN NaN NaN 10.0 1 Alfred NaN NaN NaN 15.0 2 Alfred NaN NaN NaN 18.0 3 juli NaN NaN NaN 14.0
-