In rolling().apply() of pandas, Args are cached when enigne="numba".
Is this correct behavior?
Is there any way to prevent args from being cached?
The sample code is as follows
import pandas as pd
import numba as nb
@nb.jit
def test_func(x, c):
return c
@nb.jit
def test_func2(x, c):
return c
s = pd.Series(range(5))
print("s")
print(s)
rolling_s1 = s.rolling(window=3).apply(test_func, raw=True, engine="numba", args=(100,))
print("rolling_s1")
display(rolling_s1)
rolling_s2 = s.rolling(window=3).apply(test_func, raw=True, engine="numba", args=(-100,))
print("rolling_s2")
display(rolling_s2)
rolling_s3 = s.rolling(window=3).apply(test_func2, raw=True, engine="numba", args=(-100,))
print("rolling_s3")
display(rolling_s3)
print("test_func(None, 200)")
print(test_func(None, 200))
print("test_func2(None, -200)")
print(test_func2(None, -200))
The results of the execution are as follows
s
0 0
1 1
2 2
3 3
4 4
dtype: int64
rolling_s1
0 NaN
1 NaN
2 100.0
3 100.0
4 100.0
dtype: float64
rolling_s2
0 NaN
1 NaN
2 100.0
3 100.0
4 100.0
dtype: float64
rolling_s3
0 NaN
1 NaN
2 -100.0
3 -100.0
4 -100.0
dtype: float64
test_func(None, 200)
200
test_func2(None, -200)
-200
The value of rollig_s2 should be -100, but it is 100.