aboutsummaryrefslogtreecommitdiff
path: root/src/argaze.test/DataStructures.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/argaze.test/DataStructures.py')
-rw-r--r--src/argaze.test/DataStructures.py86
1 files changed, 43 insertions, 43 deletions
diff --git a/src/argaze.test/DataStructures.py b/src/argaze.test/DataStructures.py
index 8533af3..b30c560 100644
--- a/src/argaze.test/DataStructures.py
+++ b/src/argaze.test/DataStructures.py
@@ -11,7 +11,7 @@ import unittest
from dataclasses import dataclass, field
import os
-from argaze import DataStructures
+from argaze import DataFeatures
import pandas
import numpy
@@ -25,7 +25,7 @@ def random_data_buffer(size, data_keys):
import random
import time
- ts_buffer = DataStructures.TimeStampedBuffer()
+ ts_buffer = DataFeatures.TimeStampedBuffer()
for i in range(0, size):
@@ -54,27 +54,27 @@ class TestTimeStampedBufferClass(unittest.TestCase):
"""Test TimeStampedBuffer creation."""
# Check TimeStampedBuffer length after creation
- self.assertEqual(len(DataStructures.TimeStampedBuffer()), 0)
- self.assertEqual(len(DataStructures.TimeStampedBuffer({0: ""})), 1)
- self.assertEqual(len(DataStructures.TimeStampedBuffer({0.1: ""})), 1)
- self.assertEqual(len(DataStructures.TimeStampedBuffer({0: "A", 1: "B"})), 2)
+ self.assertEqual(len(DataFeatures.TimeStampedBuffer()), 0)
+ self.assertEqual(len(DataFeatures.TimeStampedBuffer({0: ""})), 1)
+ self.assertEqual(len(DataFeatures.TimeStampedBuffer({0.1: ""})), 1)
+ self.assertEqual(len(DataFeatures.TimeStampedBuffer({0: "A", 1: "B"})), 2)
# Check TimeStampedBuffer keys after creation
- self.assertEqual(list(DataStructures.TimeStampedBuffer().keys()), [])
- self.assertEqual(list(DataStructures.TimeStampedBuffer({0: ""}).keys()), [0])
- self.assertEqual(list(DataStructures.TimeStampedBuffer({0.1: ""}).keys()), [0.1])
- self.assertEqual(list(DataStructures.TimeStampedBuffer({0: "A", 1: "B"}).keys()), [0, 1])
+ self.assertEqual(list(DataFeatures.TimeStampedBuffer().keys()), [])
+ self.assertEqual(list(DataFeatures.TimeStampedBuffer({0: ""}).keys()), [0])
+ self.assertEqual(list(DataFeatures.TimeStampedBuffer({0.1: ""}).keys()), [0.1])
+ self.assertEqual(list(DataFeatures.TimeStampedBuffer({0: "A", 1: "B"}).keys()), [0, 1])
# Check TimeStampedBuffer items after creation
- self.assertEqual(list(DataStructures.TimeStampedBuffer().items()), [])
- self.assertEqual(list(DataStructures.TimeStampedBuffer({0: ""}).items()), [(0, "")])
- self.assertEqual(list(DataStructures.TimeStampedBuffer({0.1: ""}).items()), [(0.1, "")])
- self.assertEqual(list(DataStructures.TimeStampedBuffer({0: "A", 1: "B"}).items()), [(0, "A"), (1, "B")])
+ self.assertEqual(list(DataFeatures.TimeStampedBuffer().items()), [])
+ self.assertEqual(list(DataFeatures.TimeStampedBuffer({0: ""}).items()), [(0, "")])
+ self.assertEqual(list(DataFeatures.TimeStampedBuffer({0.1: ""}).items()), [(0.1, "")])
+ self.assertEqual(list(DataFeatures.TimeStampedBuffer({0: "A", 1: "B"}).items()), [(0, "A"), (1, "B")])
# Check that TimeStampedBuffer creation fails when keys are not numbers
with self.assertRaises(AssertionError):
- DataStructures.TimeStampedBuffer({"first": ""})
+ DataFeatures.TimeStampedBuffer({"first": ""})
def test_from_dataframe(self):
"""Test TimeStampedBuffer creation from pandas dataframe."""
@@ -82,7 +82,7 @@ class TestTimeStampedBufferClass(unittest.TestCase):
ts_buffer = random_data_buffer(10, ["data_A", "data_B", "data_C"])
# Check dataframe conversion
- ts_buffer_from_df = DataStructures.TimeStampedBuffer.from_dataframe(ts_buffer.as_dataframe())
+ ts_buffer_from_df = DataFeatures.TimeStampedBuffer.from_dataframe(ts_buffer.as_dataframe())
self.assertEqual(len(ts_buffer_from_df), 10)
@@ -94,49 +94,49 @@ class TestTimeStampedBufferClass(unittest.TestCase):
json_filepath = os.path.join(current_directory, 'utils/ts_buffer.json')
# Load TimeStampedBuffer from json file
- ts_buffer = DataStructures.TimeStampedBuffer.from_json(json_filepath)
+ ts_buffer = DataFeatures.TimeStampedBuffer.from_json(json_filepath)
self.assertEqual(len(ts_buffer), 3)
def test___repr__(self):
"""Test TimeStampedBuffer string representation."""
- self.assertEqual(repr(DataStructures.TimeStampedBuffer()), "{}")
- self.assertEqual(repr(DataStructures.TimeStampedBuffer({0: ""})), "{\"0\": \"\"}")
- self.assertEqual(repr(DataStructures.TimeStampedBuffer({0.1: ""})), "{\"0.1\": \"\"}")
+ self.assertEqual(repr(DataFeatures.TimeStampedBuffer()), "{}")
+ self.assertEqual(repr(DataFeatures.TimeStampedBuffer({0: ""})), "{\"0\": \"\"}")
+ self.assertEqual(repr(DataFeatures.TimeStampedBuffer({0.1: ""})), "{\"0.1\": \"\"}")
data = BasicDataClass((123, 456))
- ts_buffer = DataStructures.TimeStampedBuffer({0: data})
+ ts_buffer = DataFeatures.TimeStampedBuffer({0: data})
self.assertEqual(repr(ts_buffer), "{\"0\": {\"value\": [123, 456]}}")
array = numpy.zeros(3)
- ts_buffer = DataStructures.TimeStampedBuffer({0: array})
+ ts_buffer = DataFeatures.TimeStampedBuffer({0: array})
self.assertEqual(repr(ts_buffer), "{\"0\": [0.0, 0.0, 0.0]}")
def test___str__(self):
"""Test TimeStampedBuffer string representation."""
- self.assertEqual(str(DataStructures.TimeStampedBuffer()), "{}")
- self.assertEqual(str(DataStructures.TimeStampedBuffer({0: ""})), "{\"0\": \"\"}")
- self.assertEqual(str(DataStructures.TimeStampedBuffer({0.1: ""})), "{\"0.1\": \"\"}")
+ self.assertEqual(str(DataFeatures.TimeStampedBuffer()), "{}")
+ self.assertEqual(str(DataFeatures.TimeStampedBuffer({0: ""})), "{\"0\": \"\"}")
+ self.assertEqual(str(DataFeatures.TimeStampedBuffer({0.1: ""})), "{\"0.1\": \"\"}")
data = BasicDataClass((123, 456))
- ts_buffer = DataStructures.TimeStampedBuffer({0: data})
+ ts_buffer = DataFeatures.TimeStampedBuffer({0: data})
self.assertEqual(str(ts_buffer), "{\"0\": {\"value\": [123, 456]}}")
array = numpy.zeros(3)
- ts_buffer = DataStructures.TimeStampedBuffer({0: array})
+ ts_buffer = DataFeatures.TimeStampedBuffer({0: array})
self.assertEqual(str(ts_buffer), "{\"0\": [0.0, 0.0, 0.0]}")
def test_append(self):
"""Test TimeStampedBuffer append method."""
- ts_buffer = DataStructures.TimeStampedBuffer({0: "A", 1: "B"})
- ts_buffer_next = DataStructures.TimeStampedBuffer({2: "C", 3: "D"})
+ ts_buffer = DataFeatures.TimeStampedBuffer({0: "A", 1: "B"})
+ ts_buffer_next = DataFeatures.TimeStampedBuffer({2: "C", 3: "D"})
self.assertEqual(len(ts_buffer.append(ts_buffer_next)), 4)
self.assertEqual(list(ts_buffer.append(ts_buffer_next).keys()), [0, 1, 2, 3])
@@ -144,17 +144,17 @@ class TestTimeStampedBufferClass(unittest.TestCase):
def test_first(self):
"""Test TimeStampedBuffer first property."""
- self.assertEqual(DataStructures.TimeStampedBuffer({0: "A", 1: "B"}).first, (0, "A"))
+ self.assertEqual(DataFeatures.TimeStampedBuffer({0: "A", 1: "B"}).first, (0, "A"))
# Check that accessing to first item of an empty TimeStampedBuffer fails
with self.assertRaises(IndexError):
- DataStructures.TimeStampedBuffer().first
+ DataFeatures.TimeStampedBuffer().first
def test_pop_first(self):
"""Test TimeStampedBuffer pop_first method."""
- ts_buffer = DataStructures.TimeStampedBuffer({0: "A", 1: "B"})
+ ts_buffer = DataFeatures.TimeStampedBuffer({0: "A", 1: "B"})
self.assertEqual(ts_buffer.pop_first(), (0, "A"))
self.assertEqual(len(ts_buffer), 1)
@@ -163,7 +163,7 @@ class TestTimeStampedBufferClass(unittest.TestCase):
def test_pop_last_until(self):
"""Test TimeStampedBuffer pop_last_until method."""
- ts_buffer = DataStructures.TimeStampedBuffer({0: "A", 1: "B", 2: "C", 3: "D"})
+ ts_buffer = DataFeatures.TimeStampedBuffer({0: "A", 1: "B", 2: "C", 3: "D"})
# Check pop until an existing timestamp
pop_last_until_2 = ts_buffer.pop_last_until(2)
@@ -173,7 +173,7 @@ class TestTimeStampedBufferClass(unittest.TestCase):
self.assertEqual(ts_buffer.first, (2, "C"))
# Check first until an none existing timestamp
- ts_buffer = DataStructures.TimeStampedBuffer({0: "A", 1: "B", 2: "C", 3: "D"})
+ ts_buffer = DataFeatures.TimeStampedBuffer({0: "A", 1: "B", 2: "C", 3: "D"})
pop_last_until_1dot5 = ts_buffer.pop_last_until(1.5)
@@ -184,7 +184,7 @@ class TestTimeStampedBufferClass(unittest.TestCase):
def test_pop_last_before(self):
"""Test TimeStampedBuffer pop_last_before method."""
- ts_buffer = DataStructures.TimeStampedBuffer({0: "A", 1: "B", 2: "C", 3: "D"})
+ ts_buffer = DataFeatures.TimeStampedBuffer({0: "A", 1: "B", 2: "C", 3: "D"})
# Check pop until an existing timestamp
last_before_2 = ts_buffer.pop_last_before(2)
@@ -194,7 +194,7 @@ class TestTimeStampedBufferClass(unittest.TestCase):
self.assertEqual(ts_buffer.first, (2, "C"))
# Check pop until an none existing timestamp
- ts_buffer = DataStructures.TimeStampedBuffer({0: "A", 1: "B", 2: "C", 3: "D"})
+ ts_buffer = DataFeatures.TimeStampedBuffer({0: "A", 1: "B", 2: "C", 3: "D"})
first_until_1dot5 = ts_buffer.pop_last_before(1.5)
@@ -205,17 +205,17 @@ class TestTimeStampedBufferClass(unittest.TestCase):
def test_last(self):
"""Test TimeStampedBuffer last property."""
- self.assertEqual(DataStructures.TimeStampedBuffer({0: "A", 1: "B"}).last, (1, "B"))
+ self.assertEqual(DataFeatures.TimeStampedBuffer({0: "A", 1: "B"}).last, (1, "B"))
# Check that accessing to last item of an empty TimeStampedBuffer fails
with self.assertRaises(IndexError):
- DataStructures.TimeStampedBuffer().last
+ DataFeatures.TimeStampedBuffer().last
def test_pop_last(self):
"""Test TimeStampedBuffer pop_last method."""
- ts_buffer = DataStructures.TimeStampedBuffer({0: "A", 1: "B"})
+ ts_buffer = DataFeatures.TimeStampedBuffer({0: "A", 1: "B"})
self.assertEqual(ts_buffer.pop_last(), (1, "B"))
self.assertEqual(len(ts_buffer), 1)
@@ -224,7 +224,7 @@ class TestTimeStampedBufferClass(unittest.TestCase):
def test_get_first_from(self):
"""Test TimeStampedBuffer get_first_from method."""
- ts_buffer = DataStructures.TimeStampedBuffer({0: "A", 1: "B", 2: "C", 3: "D"})
+ ts_buffer = DataFeatures.TimeStampedBuffer({0: "A", 1: "B", 2: "C", 3: "D"})
get_first_from_1 = ts_buffer.get_first_from(1)
@@ -247,7 +247,7 @@ class TestTimeStampedBufferClass(unittest.TestCase):
def test_get_last_before(self):
"""Test TimeStampedBuffer get_last_before method."""
- ts_buffer = DataStructures.TimeStampedBuffer({0: "A", 1: "B", 2: "C", 3: "D"})
+ ts_buffer = DataFeatures.TimeStampedBuffer({0: "A", 1: "B", 2: "C", 3: "D"})
get_last_before_2 = ts_buffer.get_last_before(2)
@@ -271,7 +271,7 @@ class TestTimeStampedBufferClass(unittest.TestCase):
def test_get_last_until(self):
"""Test TimeStampedBuffer get_last_until method."""
- ts_buffer = DataStructures.TimeStampedBuffer({0: "A", 1: "B", 2: "C", 3: "D"})
+ ts_buffer = DataFeatures.TimeStampedBuffer({0: "A", 1: "B", 2: "C", 3: "D"})
get_last_until_2 = ts_buffer.get_last_until(2)
@@ -336,7 +336,7 @@ class TestTimeStampedBufferClass(unittest.TestCase):
# Check dataframe conversion with dataclass
data = BasicDataClass((123, 456))
- ts_buffer_dataframe = DataStructures.TimeStampedBuffer({0: data}).as_dataframe()
+ ts_buffer_dataframe = DataFeatures.TimeStampedBuffer({0: data}).as_dataframe()
self.assertEqual(ts_buffer_dataframe.index.name, "timestamp")
self.assertEqual(ts_buffer_dataframe.index.size, 1)