How to use the streamz.dataframe.aggregations function in streamz

To help you get started, we’ve selected a few streamz examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github python-streamz / streamz / streamz / dataframe / core.py View on Github external
def var(self, ddof=1):
        """ Compute variance of elements within window """
        return self._known_aggregation(aggregations.Var(ddof=ddof))
github python-streamz / streamz / streamz / dataframe / core.py View on Github external
# Compute example
        state = agg.initial(self.root.example, grouper=grouper_example)
        if hasattr(grouper_example, 'iloc'):
            grouper_example = grouper_example.iloc[:0]
        elif isinstance(grouper_example, (np.ndarray, pd.Index)):
            grouper_example = grouper_example[:0]
        _, example = agg.on_new(state,
                                self.root.example.iloc[:0],
                                grouper=grouper_example)

        if self.n is not None:
            diff = aggregations.diff_iloc
            window = self.n
        elif self.value is not None:
            diff = aggregations.diff_loc
            window = self.value

        outstream = stream.accumulate(aggregations.windowed_groupby_accumulator,
                                      agg=agg,
                                      start=None,
                                      returns_state=True,
                                      diff=diff,
                                      window=window)

        for typ, s_type in _stream_types[stream_type]:
            if isinstance(example, typ):
                return s_type(outstream, example)
        return Streaming(outstream, example, stream_type=stream_type)
github python-streamz / streamz / streamz / dataframe / core.py View on Github external
def apply(self, func):
        """ Apply an arbitrary function over each window of data """
        result = self._known_aggregation(aggregations.Full())
        return result.map_partitions(func, result)
github python-streamz / streamz / streamz / dataframe / core.py View on Github external
def count(self):
        """ Count elements within window """
        return self._known_aggregation(aggregations.Count())
github python-streamz / streamz / streamz / dataframe / core.py View on Github external
def sum(self):
        """ Sum frame """
        return self.accumulate_partitions(aggregations.accumulator,
                                          agg=aggregations.Sum(),
                                          start=None, stream_type='updating',
                                          returns_state=True)
github python-streamz / streamz / streamz / dataframe / core.py View on Github external
if hasattr(grouper_example, 'iloc'):
            grouper_example = grouper_example.iloc[:0]
        elif isinstance(grouper_example, (np.ndarray, pd.Index)):
            grouper_example = grouper_example[:0]
        _, example = agg.on_new(state,
                                self.root.example.iloc[:0],
                                grouper=grouper_example)

        if self.n is not None:
            diff = aggregations.diff_iloc
            window = self.n
        elif self.value is not None:
            diff = aggregations.diff_loc
            window = self.value

        outstream = stream.accumulate(aggregations.windowed_groupby_accumulator,
                                      agg=agg,
                                      start=None,
                                      returns_state=True,
                                      diff=diff,
                                      window=window)

        for typ, s_type in _stream_types[stream_type]:
            if isinstance(example, typ):
                return s_type(outstream, example)
        return Streaming(outstream, example, stream_type=stream_type)
github python-streamz / streamz / streamz / dataframe / core.py View on Github external
def _known_aggregation(self, agg):
        if self.n is not None:
            diff = aggregations.diff_iloc
            window = self.n
        elif self.value is not None:
            diff = aggregations.diff_loc
            window = self.value
        return self.root.accumulate_partitions(aggregations.window_accumulator,
                                              diff=diff,
                                              window=window,
                                              agg=agg,
                                              start=None,
                                              returns_state=True)
github python-streamz / streamz / streamz / dataframe / core.py View on Github external
def count(self):
        """ Groupby-count """
        return self._accumulate(aggregations.GroupbyCount)
github python-streamz / streamz / streamz / dataframe / core.py View on Github external
def size(self):
        """ Number of elements within window """
        return self._known_aggregation(aggregations.Size())
github python-streamz / streamz / streamz / dataframe / core.py View on Github external
else:
            stream = self.root.stream
            grouper_example = self.grouper
            agg = Agg(self.index, grouper=self.grouper, **kwargs)

        # Compute example
        state = agg.initial(self.root.example, grouper=grouper_example)
        if hasattr(grouper_example, 'iloc'):
            grouper_example = grouper_example.iloc[:0]
        elif isinstance(grouper_example, (np.ndarray, pd.Index)):
            grouper_example = grouper_example[:0]
        _, example = agg.on_new(state,
                                self.root.example.iloc[:0],
                                grouper=grouper_example)

        outstream = stream.accumulate(aggregations.groupby_accumulator,
                                      agg=agg,
                                      start=None,
                                      returns_state=True)

        for typ, s_type in _stream_types[stream_type]:
            if isinstance(example, typ):
                return s_type(outstream, example)
        return Streaming(outstream, example, stream_type=stream_type)