Commit 99ee78f1 authored by Bert Palm's avatar Bert Palm 🎇

absolutly pandas conform tested - forward also works like pandas forward-hack,...

absolutly pandas conform tested - forward also works like pandas forward-hack, center is also tested
parent ec80fe8f
Pipeline #11305 passed with stage
in 5 minutes and 40 seconds
......@@ -16,11 +16,6 @@ def data_():
s = pd.concat([s1, s2]).sort_index()
s.name = 's'
s[15] = np.nan
# s1 = pd.Series(1., index=pd.date_range("1999/12", periods=4, freq='1M') + pd.Timedelta('1d'))
# s2 = pd.Series(1., index=pd.date_range('2000/05/15', periods=2, freq='1d'))
# s = pd.concat([s1, s2]).sort_index()
# s.name = 's'
# s[4] = np.nan
return s
......@@ -43,8 +38,7 @@ def make_dt_kws():
for window in range(1, len_s + 3):
for min_periods in [None] + list(range(window + 1)):
for win in [f'{window}d', f'{window * 31}d']:
for center in [False, True]:
l.append(dict(window=win, min_periods=min_periods, center=center, closed=closed))
l.append(dict(window=win, min_periods=min_periods, closed=closed))
return l
......@@ -94,10 +88,7 @@ def test_pandas_conform_num(data, kws):
@pytest.mark.parametrize("kws", make_dt_kws())
def test_pandas_conform_dt(data, kws):
if kws.get('center', False) is True:
pytest.skip('pandas has no center on dt-index')
else:
runtest_for_kw_combi(data, kws)
runtest_for_kw_combi(data, kws)
@pytest.mark.parametrize("kws", make_num_kws())
......@@ -109,22 +100,42 @@ def test_forward_num(data, kws):
@pytest.mark.parametrize("kws", make_dt_kws())
def test_forward_dt(data, kws):
kws.update(forward=True)
if kws.get('center', False) is True:
pytest.skip('pandas has no center on dt-index')
else:
runtest_for_kw_combi(data, kws)
# def test_centering_w_dtindex():
# s = pd.Series(0., index=pd.date_range("2000", periods=10, freq='1H'))
# s[4:7] = 1
#
# w = 2
# pd_kw= dict(window=w, center=True, min_periods=None)
# our_kw = dict(window=f'{w}h', center=True, closed='both')
# expected = s.rolling(**pd_kw).sum()
# result = customRoller(s, **our_kw, expand=False).sum()
# df = pd.DataFrame()
# df['res'] = result
# df['exp'] = expected
# print(df)
runtest_for_kw_combi(data, kws)
def dt_center_kws():
l = []
for window in range(2, 10, 2):
for min_periods in range(1, window + 1):
l.append(dict(window=window, min_periods=min_periods))
return l
@pytest.mark.parametrize("kws", dt_center_kws())
def test_centering_w_dtindex(kws):
print(kws)
s = pd.Series(0., index=pd.date_range("2000", periods=10, freq='1H'))
s[4:7] = 1
w = kws.pop('window')
mp = kws.pop('min_periods')
pd_kw = dict(window=w, center=True, min_periods=mp)
our_kw = dict(window=f'{w}h', center=True, closed='both', min_periods=mp)
expected = s.rolling(**pd_kw).sum()
result = customRoller(s, **our_kw).sum()
success = check_series(result, expected)
if not success:
print_diff(s, result, expected)
assert False
w -= 1
mp -= 1
pd_kw = dict(window=w, center=True, min_periods=mp)
our_kw = dict(window=f'{w}h', center=True, closed='neither', min_periods=mp)
expected = s.rolling(**pd_kw).sum()
result = customRoller(s, **our_kw).sum()
success = check_series(result, expected)
if not success:
print_diff(s, result, expected)
assert False
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment