Beispiel #1
0
    def test_class_init_(self):
        """Test class initialization."""

        self.assertEqual(len(self.tssdict), 3)

        tmp_ts0 = Timeseries()
        tmp_ts1 = Timeseries()
        tmp_ts2 = Timeseries()

        tmp_ts0.key = "ts0"
        tmp_ts1.key = "ts1"
        tmp_ts2.key = "ts2"

        tssdict = TssDict([tmp_ts0, tmp_ts1, tmp_ts2])

        self.assertEqual(len(tssdict), 3)

        tssdict = TssDict()

        tssdict["ts0"] = tmp_ts0
        tssdict["ts1"] = tmp_ts1
        tssdict["ts2"] = tmp_ts2

        self.assertEqual(len(tssdict), 3)

        tssdict = TssDict(
            {
                tmp_ts0.key: tmp_ts0,
                tmp_ts1.key: tmp_ts1,
                tmp_ts2.key: tmp_ts2,
            }
        )

        self.assertEqual(len(tssdict), 3)
Beispiel #2
0
    def test_tssdict_min_date(self):
        """Tests min date """

        # First add a timeseries that is earlier than the others
        tmp_ts0 = Timeseries()
        tmp_ts0.key = "First"

        tmp_ts0.dseries = datetime(2014, 12, 31).toordinal() - np.arange(10)
        tmp_ts0.tseries = np.arange(10)
        tmp_ts0.make_arrays()

        self.tssdict[tmp_ts0.key] = tmp_ts0

        self.assertTupleEqual(
            self.tssdict.min_date(), (date(2014, 12, 22), "First")
        )

        tmp_nodata = Timeseries()
        tmp_nodata.key = "nothing"
        tssdict = TssDict()
        tssdict[tmp_nodata.key] = tmp_nodata

        self.assertTupleEqual(tssdict.min_date(), (None, "nothing"))

        tssdict = TssDict()

        # none timeseries list
        tssdict["test"] = [
            date(2014, 12, 31) + timedelta(days=i) for i in range(10)
        ]
        tssdict["test1"] = [
            date(2013, 12, 31) + timedelta(days=i) for i in range(10)
        ]
        self.assertRaises(ValueError, tssdict.min_date)
Beispiel #3
0
    def test_tssdict_combine(self):
        """
        A batch of tests combining columns to one timeseries.

        Tests check to see whether the parameters are passed down properly to
        each timeseries.
        """

        # combine(self, discard=True, pad=None)
        ts_new, _ = self.tssdict.combine(discard=True, pad=None)

        # shape corresponds to the shortest length
        self.assertEqual(
            ts_new.tseries.shape[0], self.ts_short.tseries.shape[0]
        )

        self.assertEqual(ts_new.tseries.shape[1], 3)

        # combine(self, discard=False, pad=0)
        ts_new, _ = self.tssdict.combine(discard=False, pad=0)

        # shape corresponds to the longest length
        self.assertEqual(
            ts_new.tseries.shape[0], self.ts_long.tseries.shape[0]
        )

        self.assertEqual(ts_new.tseries.shape[1], 3)

        # test with TssList
        tmp_ts0 = Timeseries()
        tmp_ts0.key = "First"

        tmp_ts0.dseries = datetime(2014, 12, 31).toordinal() - np.arange(10)
        tmp_ts0.tseries = np.arange(10)
        tmp_ts0.make_arrays()

        tmp_ts1 = Timeseries()
        tmp_ts1.key = "Second"

        tmp_ts1.dseries = datetime(2014, 12, 31).toordinal() - np.arange(10)
        tmp_ts1.tseries = np.arange(10)
        tmp_ts1.make_arrays()

        tssdict = TssDict(TssList([tmp_ts0, tmp_ts1]))

        ts, _ = tssdict.combine()

        self.assertTupleEqual(ts.tseries.shape, (10, 2))

        # test with TssDict
        tssdict = TssDict(TssDict([tmp_ts0, tmp_ts1]))

        ts, _ = tssdict.combine()
        self.assertTupleEqual(ts.tseries.shape, (10, 2))