From 6a5780bb80933a4e703d9f3b820ecfb226ea8f6d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Piotr=20Ma=C5=9Blanka?= <piotr.maslanka@henrietta.com.pl>
Date: Thu, 24 Jun 2021 18:27:28 +0200
Subject: [PATCH] `TimeSeries.get_current_value` will correctly raise
 `ValueError` instead of returning None

---
 README.md            | 1 +
 setup.cfg            | 2 +-
 tempsdb/series.pyx   | 3 +++
 tests/test_series.py | 3 +++
 4 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/README.md b/README.md
index 22cf48a..91fd2a3 100644
--- a/README.md
+++ b/README.md
@@ -61,6 +61,7 @@ Then copy your resulting wheel and install it via pip on the target system.
   `direct_bytes` for compatibility with `VarlenSeries`.
   It's value is ignored
 * more class constructors use explicit typing - faster tempsdb
+* `TimeSeries.get_current_value` will correctly raise `ValueError` instead of returning None
 
 ## v0.5.4
 
diff --git a/setup.cfg b/setup.cfg
index 826a120..86e9c08 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -1,7 +1,7 @@
 # coding: utf-8
 [metadata]
 name = tempsdb
-version = 0.6a4
+version = 0.6a5
 long-description = file: README.md
 long-description-content-type = text/markdown; charset=UTF-8
 license_files = LICENSE
diff --git a/tempsdb/series.pyx b/tempsdb/series.pyx
index d04ad34..d0d9ca0 100644
--- a/tempsdb/series.pyx
+++ b/tempsdb/series.pyx
@@ -48,6 +48,9 @@ cdef class TimeSeries:
         cdef:
             Iterator it = self.iterate_range(self.last_chunk.max_ts, self.last_chunk.max_ts)
             tuple tpl = it.next_item()
+
+        if tpl is None:
+            raise ValueError('Series is empty!')
         try:
             return tpl
         finally:
diff --git a/tests/test_series.py b/tests/test_series.py
index 66f0313..a7f192f 100644
--- a/tests/test_series.py
+++ b/tests/test_series.py
@@ -6,6 +6,9 @@ class TestSeries(unittest.TestCase):
     def test_write_series(self):
         from tempsdb.series import create_series
         series = create_series('test3', 'test3', 10, 4096)
+
+        self.assertRaises(ValueError, series.get_current_value)
+
         for i in range(8000):
             series.append(i, b'\x00'*10)
 
-- 
GitLab