aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/argaze/DataStructures.py14
1 files changed, 6 insertions, 8 deletions
diff --git a/src/argaze/DataStructures.py b/src/argaze/DataStructures.py
index 2a8aed1..08bcac9 100644
--- a/src/argaze/DataStructures.py
+++ b/src/argaze/DataStructures.py
@@ -72,11 +72,7 @@ class TimeStampedBuffer(collections.OrderedDict):
"""Pop all item until a given timestamped value and return the last poped item."""
# get last timestamp before given timestamp
- earliest_ts = self.get_last_before(ts)
-
- # when no timestamped have been found
- if earliest_ts == None:
- raise KeyError
+ earliest_ts, earliest_value = self.get_last_before(ts)
popep_ts, poped_value = self.pop_first()
@@ -95,7 +91,7 @@ class TimeStampedBuffer(collections.OrderedDict):
return self.popitem(last=True)
- def get_last_before(self, ts) -> Tuple[TimeStampType, DataType] | None:
+ def get_last_before(self, ts) -> Tuple[TimeStampType, DataType]:
"""Retreive last item timestamp before a given timestamp value."""
ts_list = list(self.keys())
@@ -103,11 +99,13 @@ class TimeStampedBuffer(collections.OrderedDict):
if last_before_index >= 0:
- return ts_list[last_before_index]
+ last_before_ts = ts_list[last_before_index]
+
+ return last_before_ts, self[last_before_ts]
else:
- return None
+ raise KeyError(f'No data stored before {ts} timestamp.')
def export_as_json(self, filepath):
"""Write buffer content into a json file."""