Skip to content

Instantly share code, notes, and snippets.

@MarwanDebbiche
Created October 15, 2020 15:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MarwanDebbiche/ab059ae2eb9374a4c321b5c30bfbf79d to your computer and use it in GitHub Desktop.
Save MarwanDebbiche/ab059ae2eb9374a4c321b5c30bfbf79d to your computer and use it in GitHub Desktop.
import pandas as pd
import numpy as np
import pytest
from tsgen import TimeSerie
@pytest.fixture
def ts_monthly_constant():
start = "2020"
end = "2021"
freq = "1M"
index = pd.date_range(start=start, end=end, freq=freq)
return TimeSerie(index=index, y=np.linspace(1, 1, len(index)))
@pytest.fixture
def ts_monthly_1():
start = "2020"
end = "2021"
freq = "1M"
index = pd.date_range(start=start, end=end, freq=freq)
return TimeSerie(
index=index,
y=np.random.randn(len(index))
)
@pytest.fixture
def ts_monthly_2():
start = "2020"
end = "2021"
freq = "1M"
index = pd.date_range(start=start, end=end, freq=freq)
return TimeSerie(
index=index,
y=np.random.randn(len(index))
)
@pytest.fixture
def ts_daily():
start = "2020"
end = "2021"
freq = "1D"
index = pd.date_range(start=start, end=end, freq=freq)
return TimeSerie(
index=index,
y=np.random.randn(len(index))
)
def test_len(ts_monthly_1, ts_daily):
assert len(ts_monthly_1) == 12
# 2020 is a leap year and 2021-01-01 is included
assert len(ts_daily) == 367
def test_addition(ts_monthly_1, ts_monthly_2, ts_monthly_constant):
assert (ts_monthly_1 + ts_monthly_2) == (ts_monthly_2 + ts_monthly_1)
assert (ts_monthly_1 + ts_monthly_constant) == (ts_monthly_1 + 1)
# this line fails if we don't implement a __radd__ method:
assert (1 + ts_monthly_1) == (ts_monthly_1 + 1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment