Real tail of stream (last n elements)
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 32/100
- Issue type
- Feature
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- pandas, python
- Domain
- stream-processing
Research direction
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.
Written by the indexing model from the issue text.
Description
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.
- Dominant language
- Python
- Stars
- 1.3k
- Forks
- 149
- PR merge metrics
- No merged PRs in 30d
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from python-streamz/streamz
-
Difficulty 3/5 1-2 days Newbie friendliness 35/100
python-streamz/streamz#481 · 4 comments ·
-
Combining the streamz.Stream.filenames() and streamz.Stream.from_textfile() using dask scatter? Open
Difficulty 5/5 Over a week Newbie friendliness 25/100
python-streamz/streamz#480 · 2 comments ·
-
Difficulty 5/5 Over a week Newbie friendliness 20/100
python-streamz/streamz#479 · 1 comment ·
-
Difficulty 5/5 Over a week Newbie friendliness 20/100
python-streamz/streamz#478 · 6 comments ·
-
Difficulty 4/5 3-5 days Newbie friendliness 10/100
python-streamz/streamz#476 · 17 comments · 2 reactions ·
All issues in python-streamz/streamz
Similar issues
-
documentation help wanted
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
simonw/sqlite-utils#872 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100