|
|
@ -1,6 +1,7 @@ |
|
|
|
import datetime |
|
|
|
|
|
|
|
import pytest |
|
|
|
|
|
|
|
from pyfacts import ( |
|
|
|
AllFrequencies, |
|
|
|
Frequency, |
|
|
@ -340,8 +341,23 @@ class TestExpand: |
|
|
|
|
|
|
|
|
|
|
|
class TestShrink: |
|
|
|
# TODO |
|
|
|
pass |
|
|
|
def test_daily_to_smaller(self, create_test_data): |
|
|
|
ts_data = create_test_data(AllFrequencies.D, num=1000) |
|
|
|
ts = TimeSeries(ts_data, "D") |
|
|
|
shrunk_ts_w = ts.shrink("W", "ffill") |
|
|
|
shrunk_ts_m = ts.shrink("M", "ffill") |
|
|
|
assert len(shrunk_ts_w) == 143 |
|
|
|
assert len(shrunk_ts_m) == 34 |
|
|
|
|
|
|
|
def test_weekly_to_smaller(self, create_test_data): |
|
|
|
ts_data = create_test_data(AllFrequencies.W, num=300) |
|
|
|
ts = TimeSeries(ts_data, "W") |
|
|
|
tsm = ts.shrink("M", "ffill") |
|
|
|
assert len(tsm) == 70 |
|
|
|
tsmeo = ts.shrink("M", "ffill", eomonth=True) |
|
|
|
assert len(tsmeo) == 69 |
|
|
|
with pytest.raises(ValueError): |
|
|
|
ts.shrink("D", "ffill") |
|
|
|
|
|
|
|
|
|
|
|
class TestMeanReturns: |
|
|
@ -360,7 +376,7 @@ class TestTransform: |
|
|
|
ts = TimeSeries(ts_data, "D") |
|
|
|
tst = ts.transform("W", "mean") |
|
|
|
assert isinstance(tst, TimeSeries) |
|
|
|
assert len(tst) == 157 |
|
|
|
assert len(tst) == 156 |
|
|
|
assert "2017-01-30" in tst |
|
|
|
assert tst.iloc[4] == (datetime.datetime(2017, 1, 30), 1021.19) |
|
|
|
|
|
|
|