memory2: time windowing on Stream#2315
Conversation
Greptile SummaryAdds four time-windowing methods to
Confidence Score: 5/5Safe to merge — the new methods are additive, delegate entirely to the established after()/before() filter primitives, and do not touch any existing code paths. All four methods are thin, well-tested wrappers. The empty-stream guard (catching LookupError from first()) is handled correctly for static and pre-filtered streams. Test coverage is thorough, including chained relative+absolute combinations and boundary conditions. No files require special attention. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
FT["from_time(s)"] --> FT1{"s is None?"}
FT1 -->|yes| FT2["return self"]
FT1 -->|no| FT3["self.first()"]
FT3 -->|LookupError| FT4["return self (empty)"]
FT3 -->|"t0"| FT5["self.after(t0 + s)"]
FT5 --> AF["AfterFilter appended to query"]
TT["to_time(s)"] --> TT1{"s is None?"}
TT1 -->|yes| TT2["return self"]
TT1 -->|no| TT3["self.first()"]
TT3 -->|LookupError| TT4["return self (empty)"]
TT3 -->|"t0"| TT5["self.before(t0 + s)"]
TT5 --> BF["BeforeFilter appended to query"]
FTS["from_timestamp(ts)"] --> FTS1{"ts is None?"}
FTS1 -->|yes| FTS2["return self"]
FTS1 -->|no| FTS3["self.after(ts)"]
FTS3 --> AF
TTS["to_timestamp(ts)"] --> TTS1{"ts is None?"}
TTS1 -->|yes| TTS2["return self"]
TTS1 -->|no| TTS3["self.before(ts)"]
TTS3 --> BF
Reviews (3): Last reviewed commit: "memory2: from_time/to_time yield empty o..." | Re-trigger Greptile |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Add from_time/to_time (relative to the first observation) and from_timestamp/to_timestamp (absolute epoch seconds) for windowing a stream by time. A trailing to_time is a duration measured from the current start, so from_time(2).to_time(30) reads as "skip 2s, take the following 30s"; frames mix freely (from_timestamp(ts).to_time(30)). Shared base for the stream-alignment (#2306) and go2dds (#2314) branches, which both need this windowing API.
from_time/to_time resolve their anchor via first(), which raised LookupError when the stream was already empty (e.g. from_timestamp(future_ts).to_time(30) — the mixed pattern the PR advertises). Guard the eager first() so an empty slice returns an empty window, matching the lazy from_timestamp/to_timestamp. Adds a regression test.
a8bed40 to
6ab8f0a
Compare
Adds time-based windowing to
Stream- shared base both #2306 (stream alignment) and #2314 (go2dds) needfrom_time(s)/to_time(s)- relative to the first observationfrom_timestamp(ts)/to_timestamp(ts)- absolute epoch seconds