Skip to content
This repository was archived by the owner on Feb 2, 2024. It is now read-only.

Commit 41896f4

Browse files
committed
Refuse class WindowSum
1 parent 5be165c commit 41896f4

File tree

3 files changed

+48
-111
lines changed

3 files changed

+48
-111
lines changed

sdc/datatypes/hpat_pandas_series_rolling_functions.py

Lines changed: 47 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -308,8 +308,28 @@ def apply_minp(arr, ddof, minp):
308308
gen_hpat_pandas_series_rolling_ddof_impl(arr_var))
309309

310310

311-
def gen_sdc_pandas_series_rolling_impl(window_cls):
312-
"""Generate series rolling methods implementations based on window class"""
311+
@sdc_register_jitable
312+
def pop_sum(value, nfinite, result):
313+
"""Calculate the window sum without old value."""
314+
if numpy.isfinite(value):
315+
nfinite -= 1
316+
result -= value
317+
318+
return nfinite, result
319+
320+
321+
@sdc_register_jitable
322+
def put_sum(value, nfinite, result):
323+
"""Calculate the window sum with new value."""
324+
if numpy.isfinite(value):
325+
nfinite += 1
326+
result += value
327+
328+
return nfinite, result
329+
330+
331+
def gen_sdc_pandas_series_rolling_impl(pop, put, init_result=numpy.nan):
332+
"""Generate series rolling methods implementations based on pop/put funcs"""
313333
def impl(self):
314334
win = self._window
315335
minp = self._min_periods
@@ -322,19 +342,37 @@ def impl(self):
322342
chunks = parallel_chunks(length)
323343
for i in prange(len(chunks)):
324344
chunk = chunks[i]
325-
window = window_cls(win, minp)
345+
nroll = 0
346+
nfinite = 0
347+
result = init_result
326348
for idx in range(chunk.start, chunk.stop):
327-
window.roll(input_arr, idx)
328-
output_arr[idx] = window.result
329-
window.free()
349+
if nroll == 0:
350+
start = max(idx + 1 - win, 0)
351+
for j in range(start, idx):
352+
value = input_arr[j]
353+
nfinite, result = put(value, nfinite, result)
354+
nroll += 1
355+
356+
if nroll >= win:
357+
value = input_arr[idx - win]
358+
nfinite, result = pop(value, nfinite, result)
359+
360+
value = input_arr[idx]
361+
nfinite, result = put(value, nfinite, result)
362+
nroll += 1
363+
364+
if nfinite < minp:
365+
output_arr[idx] = numpy.nan
366+
else:
367+
output_arr[idx] = result
330368

331369
return pandas.Series(output_arr, input_series._index,
332370
name=input_series._name)
333371
return impl
334372

335373

336-
sdc_pandas_rolling_series_sum_impl = register_jitable(
337-
gen_sdc_pandas_series_rolling_impl(WindowSum))
374+
sdc_pandas_series_rolling_sum_impl = register_jitable(
375+
gen_sdc_pandas_series_rolling_impl(pop_sum, put_sum, init_result=0.))
338376

339377

340378
@sdc_rolling_overload(SeriesRollingType, 'apply')
@@ -648,7 +686,7 @@ def hpat_pandas_series_rolling_sum(self):
648686
ty_checker = TypeChecker('Method rolling.sum().')
649687
ty_checker.check(self, SeriesRollingType)
650688

651-
return sdc_pandas_rolling_series_sum_impl
689+
return sdc_pandas_series_rolling_sum_impl
652690

653691

654692
@sdc_rolling_overload(SeriesRollingType, 'var')

sdc/tests/tests_perf/test_perf_series_rolling.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class TestSeriesRollingMethods(TestBase):
8585
def setUpClass(cls):
8686
super().setUpClass()
8787
cls.map_ncalls_dlength = {
88-
'sum': (100, [2 * 10 ** 5]),
88+
'sum': (100, [8 * 10 ** 5]),
8989
}
9090

9191
def _test_case(self, pyfunc, name, total_data_length, data_num=1,

sdc/utilities/window_utils.py

Lines changed: 0 additions & 101 deletions
This file was deleted.

0 commit comments

Comments
 (0)