From 38fb9ca7d06f1215aa57e105a5be86a8b596a09d Mon Sep 17 00:00:00 2001 From: Gourav Kumar Date: Tue, 24 May 2022 21:11:46 +0530 Subject: [PATCH] tests fro transform method --- tests/test_fincal.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/tests/test_fincal.py b/tests/test_fincal.py index b4b8ad2..0587fdf 100644 --- a/tests/test_fincal.py +++ b/tests/test_fincal.py @@ -354,6 +354,40 @@ class TestReadCsv: pass +class TestTransform: + def test_daily_to_yearly(self, create_test_data): + ts_data = create_test_data(AllFrequencies.D, num=782, skip_weekends=True) + ts = TimeSeries(ts_data, "D") + tst = ts.transform("Y", "mean") + assert isinstance(tst, TimeSeries) + assert len(tst) == 3 + assert "2019-01-02" in tst + assert tst.iloc[2] == (datetime.datetime(2019, 1, 2), 1238.5195) + + def test_weekly_to_monthly(self, create_test_data): + ts_data = create_test_data(AllFrequencies.W, num=261) + ts = TimeSeries(ts_data, "W") + tst = ts.transform("M", "mean") + assert isinstance(tst, TimeSeries) + assert "2017-01-01" in tst + assert tst.iloc[0] == (datetime.datetime(2017, 1, 1), 1007.33) + + def test_weekly_to_qty(self, create_test_data): + ts_data = create_test_data(AllFrequencies.W, num=261) + ts = TimeSeries(ts_data, "W") + tst = ts.transform("Q", "mean") + assert len(tst) == 20 + assert "2018-01-01" in tst + assert round(tst.iloc[4][1], 2) == 1054.72 + + def test_weekly_to_yearly(self, create_test_data): + ts_data = create_test_data(AllFrequencies.W, num=261) + ts = TimeSeries(ts_data, "W") + tst = ts.transform("Y", "mean") + assert "2019-01-01" in tst + assert round(tst.iloc[2][1], 2) == 1054.50 + + class TestReturnsAgain: data = [ ("2020-01-01", 10),