File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed
Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -11,12 +11,30 @@ def total(t: ibis.Table) -> int:
1111 return t .count ().to_pyarrow ().as_py ()
1212
1313
14+ def _densify (t : ibis .Table , ts_col : str , agg_col : str ) -> ibis .Table :
15+ ts = (
16+ ibis .range (
17+ t [ts_col ].min ().as_scalar (),
18+ ibis .now ().truncate ("D" ),
19+ step = ibis .interval (days = 1 ),
20+ )
21+ .unnest ()
22+ .name (ts_col )
23+ .as_table ()
24+ )
25+
26+ return t .join (ts , ts_col , how = "outer" ).select (
27+ ** {ts_col : f"{ ts_col } _right" , agg_col : ibis ._ [agg_col ].fill_null (0 )},
28+ )
29+
30+
1431def stars_rolling (t : ibis .Table , days : int = 28 ) -> ibis .Table :
1532 t = (
1633 t .mutate (starred_at = t ["starred_at" ].truncate ("D" ))
1734 .group_by ("starred_at" )
1835 .agg (stars = ibis ._ .count ())
1936 )
37+ t = _densify (t , "starred_at" , "stars" )
2038 t = t .select (
2139 timestamp = "starred_at" ,
2240 rolling_stars = ibis ._ ["stars" ]
You can’t perform that action at this time.
0 commit comments