vp.features.sessions
Gap-based sessions per user (catalog/sessions.viv).
Part of the distribution vipyr; it runs from a checkout of the
repository. Planned on PyPI as pip install vipyr.
Signature
vp.features.sessions(df=None, n=500, gap='30min') Parameters
- df : pandas.DataFrame, default
None - The event table, rows in any order; None makes a synthetic one of n rows.
- n : int, default
500 - Rows of the synthetic table when df is None. Range: >= 1.
- gap : str, default
'30min'
Returns
A frozen SessionsResult. Iterating it gives the fields below in order; it also has
params, tests, log and check().
- frame : pandas.DataFrame
- The features, one row per input row, in the input's order and index: session_start, session_index, secs_since_start, n_prev_in_session.
| column of frame | definition |
|---|---|
session_start | time of the session's first event; with user, the session's id |
session_index | number of the user's sessions that started before this one |
secs_since_start | (ts - session_start) in seconds |
n_prev_in_session | events of the session with a time before ts (same instant excluded) |
Raises
- TypeError
- An argument of the wrong type, or an unknown keyword.
- vipyr.VivBuildError
- An ImportError: no C compiler, or the program's C does not build.
Examples
import vipyr as vp
r = vp.features.sessions() # a synthetic table; pass df= for yours
print(r.frame.head())
assert r.check() session_start session_index secs_since_start n_prev_in_session
0 2026-01-01 18:18:09 0 0.0 0
1 2026-01-02 08:52:12 1 0.0 0
2 2026-01-03 00:05:53 2 0.0 0
3 2026-01-03 03:36:31 3 0.0 0
4 2026-01-04 23:55:26 4 0.0 0Each example ran as written when these pages were generated, and the output shown is what it printed.
Checked against
- Reference
- catalog.sessions_reference: a pandas groupby().apply() with a Python loop per row, equal bit for bit; vipyr.check_point_in_time: no feature reads a row after its own time
Source
- Viv: catalog/sessions.viv
- Viv: catalog/catalog.py
- The defs it reaches and the calls between them: map of the code