cudf.core.window.rolling.Rolling.apply#

Rolling.apply(func, *args, **kwargs)#

Calculate the rolling custom aggregation function.

Parameters:
funcfunction

A user defined function that takes an 1D array as input

argstuple

unsupported.

kwargs

unsupported

See also

cudf.Series.apply

Apply an elementwise function to transform the values in the Column.

Notes

The supported Python features are listed in

https://numba.readthedocs.io/en/stable/cuda/cudapysupported.html

with these exceptions:

  • Math functions in cmath are not supported since libcudf does not have complex number support and output of cmath functions are most likely complex numbers.

  • These five functions in math are not supported since numba generates multiple PTX functions from them:

    • math.sin()

    • math.cos()

    • math.tan()

    • math.gamma()

    • math.lgamma()

  • Series with string dtypes are not supported.

  • Global variables need to be re-defined explicitly inside the udf, as numba considers them to be compile-time constants and there is no known way to obtain value of the global variable.

Examples

>>> import cudf
>>> def count_if_gt_3(window):
...     count = 0
...     for i in window:
...             if i > 3:
...                     count += 1
...     return count
...
>>> s = cudf.Series([0, 1.1, 5.8, 3.1, 6.2, 2.0, 1.5])
>>> s.rolling(3, min_periods=1).apply(count_if_gt_3)
0    0
1    0
2    1
3    2
4    3
5    2
6    1
dtype: int64