Real tail of stream (last n elements)

オープン
#415 コメント 3 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
32/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
pandas, python

調査の方向性

Start with the Stream.from_periodic example and trace the accumulate(...).to_dataframe path used to retain DataFrame batches. The issue names no source file or test, so first determine where stream accumulation and window behavior are implemented. Done means agreeing on the API and semantics for exposing the last n elements, then verifying that behavior for the shown DataFrame workflow.

索引モデルが issue の本文から書いたものです。

説明

To my knowledge there is currently no way to show (or plot) the last n elements of a Streamz DataFrame.

I think this is a very useful function for debugging, but also for slower Streamz, for example CFD results from OpenFOAM.

Here is a naive implementation:

def tail(length):
    def tail_func(x, y):
        x = x.append(y, ignore_index=True)
        return x.iloc[-length:].reset_index(drop=True)
    return tail_func

Here is an example:
(thanks for the feedback @martindurant)

import pandas as pd
from streamz import Stream
import numpy as np

names = ["Mike", "Tim", "Anna", "Kim", "Andy"]

def emitter():
    n = np.random.randint(1, 5)
    return {"name": np.random.choice(names, n), "age": np.random.randint(18, 32, n)}

stream = Stream.from_periodic(emitter, 1)
df1 = pd.DataFrame({"name": ["test"], "age": [40]})
out = stream.map(pd.DataFrame).accumulate(tail(6), start=pd.DataFrame()).to_dataframe(df1)
# out.stream.sink(print)  # optional, or some other output

stream.start()

# if using a Jupyter Lab
out

This could either be the bare representation of window or could replace the tail function. I think the name tail suits this function better than the current one. What do you think?

Implementation wise one could be much more efficient by using .loc and round robin replacing values and saving the order somewhere else, but for a first go, I would stick by the naive version.

主要言語
Python
スター
1.3k
フォーク
149
PR マージ指標
30日以内にマージされた PR はありません

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

python-streamz/streamz のほかの issue

python-streamz/streamz の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。