Esempio n. 1
0
    def test_get_by_time(self):
        series = DataSeries(keys=set(["timestamp", "v1", "v2"]))

        # time and key
        series.add({"timestamp": self.t1, "v1": 2})
        series.add({"timestamp": self.t2, "v1": 2.4})
        series.add({"timestamp": self.t2, "v2": 3.0})

        self.assertEqual(2, series.get_by_time(time=self.t1, keys="v1"))
        self.assertTrue(np.isnan(series.get_by_time(time=self.t1, keys="v2")))
        self.assertEqual(2.4, series.get_by_time(time=self.t2, keys="v1"))
        self.assertEqual(3.0, series.get_by_time(time=self.t2, keys="v2"))
        # time only
        self.assertEqual({"timestamp": self.t1, "v1": 2, "v2": np.nan}, series.get_by_time(time=self.t1))
        self.assertEqual({"timestamp": self.t2, "v1": 2.4, "v2": 3.0}, series.get_by_time(time=self.t2))
Esempio n. 2
0
    def test_override_w_same_time(self):
        series = DataSeries(keys=set(["timestamp", "v1", "v2", "v3"]))

        series.add({"timestamp": self.t1, "v1": 2, "v2": 3})
        self.assertEqual(1, series.size())
        self.assertEqual(2, series.get_by_idx(0, "v1"))
        self.assertEqual(2, series.get_by_time(self.t1, "v1"))
        self.assertEqual(3, series.get_by_idx(0, "v2"))
        self.assertEqual(3, series.get_by_time(self.t1, "v2"))
        self.assertTrue(np.isnan(series.get_by_idx(0, "v3")))
        self.assertTrue(np.isnan(series.get_by_time(self.t1, "v3")))

        series.add({"timestamp": self.t1, "v1": 2.4, "v2": 3.4, "v3": 1.1})
        self.assertEqual(1, series.size())
        self.assertEqual(2.4, series.get_by_idx(0, "v1"))
        self.assertEqual(2.4, series.get_by_time(self.t1, "v1"))
        self.assertEqual(3.4, series.get_by_idx(0, "v2"))
        self.assertEqual(3.4, series.get_by_time(self.t1, "v2"))
        self.assertEqual(1.1, series.get_by_idx(0, "v3"))
        self.assertEqual(1.1, series.get_by_time(self.t1, "v3"))

        series.add({"timestamp": self.t2, "v1": 2.6, "v2": 3.6})
        self.assertEqual(2, series.size())
        self.assertEqual(2.4, series.get_by_idx(0, "v1"))
        self.assertEqual(2.4, series.get_by_time(self.t1, "v1"))
        self.assertEqual(3.4, series.get_by_idx(0, "v2"))
        self.assertEqual(3.4, series.get_by_time(self.t1, "v2"))
        self.assertEqual(1.1, series.get_by_idx(0, "v3"))
        self.assertEqual(1.1, series.get_by_time(self.t1, "v3"))

        self.assertEqual(2.6, series.get_by_idx(1, "v1"))
        self.assertEqual(2.6, series.get_by_time(self.t2, "v1"))
        self.assertEqual(3.6, series.get_by_idx(1, "v2"))
        self.assertEqual(3.6, series.get_by_time(self.t2, "v2"))
        self.assertTrue(np.isnan(series.get_by_idx(1, "v3")))
        self.assertTrue(np.isnan(series.get_by_time(self.t2, "v3")))