Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
26b29dc
Add method keyword and validation
Dec 4, 2020
7739b57
Add sub numba table func
Dec 5, 2020
8d66fc4
Fix output result and result min_periods handling
Dec 10, 2020
db39381
Merge remote-tracking branch 'upstream/master' into feature/rolling_t…
Dec 10, 2020
b67e725
Fix cache key
Dec 10, 2020
ea89fb6
Just use transpose for axis = 1
Dec 11, 2020
87570ef
Add test comparing column and table methods
Dec 11, 2020
1477004
Test invalid series table rolling
Dec 11, 2020
c377186
Merge remote-tracking branch 'upstream/master' into feature/rolling_t…
Dec 11, 2020
9bd2d0d
Adjust some tests
Dec 11, 2020
9be922b
Add test for invalid method keyword
Dec 11, 2020
a6473a5
Notimplemented test with win_type
Dec 11, 2020
4fa7abd
wrap table method tests in a class
Dec 11, 2020
2d7a58e
Add method keyword for expanding
Dec 11, 2020
76ead37
Change caching key to handing callers from Rolling or Expanding
Dec 11, 2020
12e7c57
Test expanding table
Dec 11, 2020
93c546e
Change column to single
Dec 12, 2020
1eaad79
flake8
Dec 12, 2020
c550d8e
Merge remote-tracking branch 'upstream/master' into feature/rolling_t…
Dec 12, 2020
5d040d0
Add weighted mean example as a test
Dec 12, 2020
57fc525
black
Dec 12, 2020
84619a1
Add whatsnew and window.rst example
Dec 12, 2020
42af1c3
Merge remote-tracking branch 'upstream/master' into feature/rolling_t…
Dec 14, 2020
9f172bd
Add as of version to table
Dec 14, 2020
cfe909c
Fix typo and add wikipedia link in window.rst
Dec 14, 2020
884c7ff
Use correct type and document func output and input
Dec 14, 2020
08f23e0
Newline
Dec 14, 2020
27e9bbb
Plural -> singular
Dec 14, 2020
b4fa92c
Add noqa in rst
Dec 14, 2020
354c698
Skip if scipy isnt installed
Dec 14, 2020
6fdfef4
Add asv benchmark
Dec 14, 2020
72e50d3
Add min periods for min version build
Dec 14, 2020
bdd600c
Merge remote-tracking branch 'upstream/master' into feature/rolling_t…
Dec 14, 2020
d9aa45c
Merge remote-tracking branch 'upstream/master' into feature/rolling_t…
Dec 15, 2020
c769ea2
Merge remote-tracking branch 'upstream/master' into feature/rolling_t…
Dec 16, 2020
dde4d8e
Merge remote-tracking branch 'upstream/master' into feature/rolling_t…
Dec 16, 2020
b863dc2
Merge remote-tracking branch 'upstream/master' into feature/rolling_t…
Dec 16, 2020
c674b97
Merge remote-tracking branch 'upstream/master' into feature/rolling_t…
Dec 17, 2020
55f44af
Remove redundant 1.3 doc
Dec 17, 2020
24a80db
Remove closed and center parameterizations
Dec 17, 2020
0203d02
Merge remote-tracking branch 'upstream/master' into feature/rolling_t…
Dec 17, 2020
ba86276
Clarify doc
mroeschke Dec 22, 2020
1651616
Merge remote-tracking branch 'upstream/master' into feature/rolling_t…
mroeschke Dec 22, 2020
55156cd
Fix benchmark
mroeschke Dec 22, 2020
6ca999a
Merge remote-tracking branch 'upstream/master' into feature/rolling_t…
mroeschke Dec 22, 2020
388b837
Merge remote-tracking branch 'upstream/master' into feature/rolling_t…
mroeschke Dec 23, 2020
f4ba0c6
just use prange
mroeschke Dec 23, 2020
d37e23b
Merge remote-tracking branch 'upstream/master' into feature/rolling_t…
mroeschke Dec 23, 2020
9ad8064
Forgot decorator as part of merge conflict fixup
mroeschke Dec 23, 2020
d5eb31c
Merge remote-tracking branch 'upstream/master' into feature/rolling_t…
mroeschke Dec 23, 2020
754d71e
Merge remote-tracking branch 'upstream/master' into feature/rolling_t…
Dec 27, 2020
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix output result and result min_periods handling
  • Loading branch information
Matt Roeschke committed Dec 10, 2020
commit 8d66fc447d343853eb5609c9cdf1cfdd167bc4d7
9 changes: 6 additions & 3 deletions pandas/core/window/numba_.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ def generate_numba_table_func(
"""
nopython, nogil, parallel = get_jit_arguments(engine_kwargs, kwargs)

# TODO: change this key
cache_key = (func, "rolling_apply")
if cache_key in NUMBA_FUNC_CACHE:
return NUMBA_FUNC_CACHE[cache_key]
Expand All @@ -206,15 +207,17 @@ def roll_table(
):
# TODO: consider axis argument, len should be replaced with axis aware result
result = np.empty(values.shape)
min_periods_mask = np.empty(values.shape)
for i in loop_range(len(result)):
start = begin[i]
stop = end[i]
window = values[start:stop, :]
count_nan = np.sum(np.isnan(window))
window = values[start:stop]
count_nan = np.sum(np.isnan(window), axis=0)
sub_result = numba_func(window, *args)
nan_mask = len(window) - count_nan >= minimum_periods
sub_result[~nan_mask] = np.nan
min_periods_mask[i, :] = nan_mask
result[i, :] = sub_result
result = np.where(min_periods_mask, result, np.nan)
return result

return roll_table
35 changes: 28 additions & 7 deletions pandas/core/window/rolling.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@
GroupbyIndexer,
VariableWindowIndexer,
)
from pandas.core.window.numba_ import generate_numba_apply_func
from pandas.core.window.numba_ import (
generate_numba_apply_func,
generate_numba_table_func,
)

if TYPE_CHECKING:
from pandas import DataFrame, Series
Expand Down Expand Up @@ -418,10 +421,17 @@ def _apply_tablewise(
if self._selected_obj.ndim == 1:
raise ValueError("method='table' not applicable for Series objects.")
obj = self._create_data(self._selected_obj)
values = self._prep_values(obj)
# Need to ensure we wrap this correctly, will return ndarray
values = self._prep_values(obj.to_numpy())
result = homogeneous_func(values)
return result
out = obj._constructor(result, index=obj.index, columns=obj.columns)

if out.shape[1] == 0 and obj.shape[1] > 0:
raise DataError("No numeric types to aggregate")
elif out.shape[1] == 0:
return obj.astype("float64")

self._insert_on_column(out, obj)
return out

def _apply(
self,
Expand Down Expand Up @@ -482,7 +492,10 @@ def calc(x):

return result

return self._apply_blockwise(homogeneous_func, name)
if self.method == "column":
return self._apply_blockwise(homogeneous_func, name)
else:
return self._apply_tablewise(homogeneous_func, name)

def aggregate(self, func, *args, **kwargs):
result, how = aggregate(self, func, *args, **kwargs)
Expand Down Expand Up @@ -1326,8 +1339,16 @@ def apply(
if maybe_use_numba(engine):
if raw is False:
raise ValueError("raw must be `True` when using the numba engine")
apply_func = generate_numba_apply_func(args, kwargs, func, engine_kwargs)
numba_cache_key = (func, "rolling_apply")
if self.method == "column":
apply_func = generate_numba_apply_func(
args, kwargs, func, engine_kwargs
)
numba_cache_key = (func, "rolling_apply_column")
else:
apply_func = generate_numba_table_func(
args, kwargs, func, engine_kwargs
)
numba_cache_key = (func, "rolling_apply_table")
elif engine in ("cython", None):
if engine_kwargs is not None:
raise ValueError("cython engine does not accept engine_kwargs")
Expand Down