1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
U
¬ý°dD+ã
@süddlmZddlZddlmZmZmZddlZddl    m
Z
ddl m Z ddl mZejdddd    d    d    d
œd d „ƒZejddd    d    d    d d    d    dd    dœdd„ƒZejdddd    d    d    d
œdd„ƒZejdddd„ƒZejddd    d    d    d d    d    dd    dœdd„ƒZdS)é)Ú annotationsN)Ú TYPE_CHECKINGÚAnyÚCallable)ÚScalar)Úimport_optional_dependency)Újit_user_function)ÚmaxsizezCallable[..., Scalar]Úbool)ÚfuncÚnopythonÚnogilÚparallelcsVt||||ƒ‰trddl‰ntdƒ‰ˆj|||ddddddddœ‡‡fd    d
„ ƒ}|S) a’
    Generate a numba jitted apply function specified by values from engine_kwargs.
 
    1. jit the user's function
    2. Return a rolling apply function with the jitted function inline
 
    Configurations specified in engine_kwargs apply to both the user's
    function _AND_ the rolling apply function.
 
    Parameters
    ----------
    func : function
        function to be applied to each window and will be JITed
    nopython : bool
        nopython to be passed into numba.jit
    nogil : bool
        nogil to be passed into numba.jit
    parallel : bool
        parallel to be passed into numba.jit
 
    Returns
    -------
    Numba function
    rNÚnumba©r r rú
np.ndarrayÚintr)ÚvaluesÚbeginÚendÚminimum_periodsÚargsÚreturnc s€t t|ƒ¡}ˆ t|ƒ¡D]^}||}||}|||…}    t t |    ¡¡}
t|    ƒ|
|krpˆ|    f|žŽ||<qtj||<q|S)N)ÚnpÚemptyÚlenÚprangeÚsumÚisnanÚnan) rrrrrÚresultÚiÚstartÚstopÚwindowÚ    count_nan©rZ
numba_func©úPd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\pandas/core/window/numba_.pyÚ
roll_apply7s  z-generate_numba_apply_func.<locals>.roll_apply©rrrrÚjit)r r r rr)r'r&r(Úgenerate_numba_apply_funcs
 r,ÚfloatÚtuple)r r rÚcomÚadjustÚ    ignore_naÚdeltasÚ    normalizec    sNtrddl‰ntdƒ‰ˆj|||dddddddœ‡‡‡‡‡‡fdd    „ ƒ}|S)
aÍ
    Generate a numba jitted ewm mean or sum function specified by values
    from engine_kwargs.
 
    Parameters
    ----------
    nopython : bool
        nopython to be passed into numba.jit
    nogil : bool
        nogil to be passed into numba.jit
    parallel : bool
        parallel to be passed into numba.jit
    com : float
    adjust : bool
    ignore_na : bool
    deltas : tuple
    normalize : bool
 
    Returns
    -------
    Numba function
    rNrrrr©rrrrrcs˜t t|ƒ¡}ddˆ}d|}ˆr*dn|}ˆ t|ƒ¡D]T}||}    ||}
||    |
…} t t| ƒ¡} | d} tt | ¡ ƒ}||kr| ntj| d<d}tdt| ƒƒD]Ø}| |}t |¡ }||7}t | ¡sb|s∐slˆr||ˆ|    |d9}n|| } |rlˆrX| |krB|| ||} ˆrB| ||} ˆrR||7}nd}n| |7} n
|rl|} ||krz| ntj| |<q¬| ||    |
…<q<|S)Nçð?ré)rrrrrrrÚrange)rrrrr ÚalphaÚ old_wt_factorÚnew_wtr!r"r#r$Ú
sub_resultÚweightedÚnobsÚold_wtÚjÚcurZis_observation©r0r/r2r1r3rr'r(ÚewmtsJ     
 
 
 
z$generate_numba_ewm_func.<locals>.ewm©rrrr+)    r r rr/r0r1r2r3rBr'rAr(Úgenerate_numba_ewm_funcNs !
&8rDzCallable[..., np.ndarray]csTt||||ƒ‰trddl‰ntdƒ‰ˆj|||dddddddœ‡‡fd    d
„ ƒ}|S) aé
    Generate a numba jitted function to apply window calculations table-wise.
 
    Func will be passed a M window size x N number of columns array, and
    must return a 1 x N number of columns array. Func is intended to operate
    row-wise, but the result will be transposed for axis=1.
 
    1. jit the user's function
    2. Return a rolling apply function with the jitted function inline
 
    Parameters
    ----------
    func : function
        function to be applied to each window and will be JITed
    nopython : bool
        nopython to be passed into numba.jit
    nogil : bool
        nogil to be passed into numba.jit
    parallel : bool
        parallel to be passed into numba.jit
 
    Returns
    -------
    Numba function
    rNrrrrr)rrrrrcsºt t|ƒ|jdf¡}t |j¡}ˆ t|ƒ¡D]r}||}||}    |||    …}
tjt |
¡dd} ˆ|
f|žŽ} t|
ƒ| |k} | ||dd…f<| ||dd…f<q2t ||tj¡}|S)Nr6r)Zaxis)    rrrÚshaperrrÚwherer)rrrrrr Zmin_periods_maskr!r"r#r$r%r;Znan_maskr&r'r(Ú
roll_tableÖs  z-generate_numba_table_func.<locals>.roll_tabler*)r r r rrGr'r&r(Úgenerate_numba_table_func°s 
rHcs8trddl‰ntdƒ‰ˆjdddd‡‡fdd„ƒ}|S)NrrTrcsFt |jd¡}ˆ |jd¡D] }|dd…|f}ˆ|ƒ||<q |S)Nr6)rrrEr)Útabler r!Ú    partition©Únan_funcrr'r(Únan_agg_with_axisùs
zBgenerate_manual_numpy_nan_agg_with_axis.<locals>.nan_agg_with_axisrC)rLrMr'rKr(Ú'generate_manual_numpy_nan_agg_with_axisòs 
rNc    sNtrddl‰ntdƒ‰ˆj|||dddddddœ‡‡‡‡‡‡fdd    „ ƒ}|S)
aß
    Generate a numba jitted ewm mean or sum function applied table wise specified
    by values from engine_kwargs.
 
    Parameters
    ----------
    nopython : bool
        nopython to be passed into numba.jit
    nogil : bool
        nogil to be passed into numba.jit
    parallel : bool
        parallel to be passed into numba.jit
    com : float
    adjust : bool
    ignore_na : bool
    deltas : tuple
    normalize: bool
 
    Returns
    -------
    Numba function
    rNrrrrr4c    sÞddˆ}d|}ˆrdn|}t |jd¡}t |j¡}|d ¡}    t |    ¡ tj¡}
t |
|k|    tj    ¡|d<t
dt |ƒƒD]T} || } t | ¡} |
|  tj¡7}
ˆ  t | ƒ¡D]}t |    |¡sª| |sވs¾ˆr|||ˆ| d9<n||    ||    |<| |r¾ˆr”|    || |krr|||    ||| ||    |<ˆrr|    |||||    |<ˆrŠ|||7<nd||<n|    || |7<qº| |rº| ||    |<qºt |
|k|    tj    ¡|| <q‚|S)Nr5r6r) rZonesrErÚcopyrZastypeÚint64rFrr7rr)rrrrr8r9r:r>r r<r=r!r@Zis_observationsr?rAr'r(Ú    ewm_table*sB     
ÿ
z0generate_numba_ewm_table_func.<locals>.ewm_tablerC)    r r rr/r0r1r2r3rQr'rAr(Úgenerate_numba_ewm_table_funcs !
&2rR)Ú
__future__rÚ    functoolsÚtypingrrrÚnumpyrZpandas._typingrZpandas.compat._optionalrZpandas.core.util.numba_rÚ    lru_cacher,rDrHrNrRr'r'r'r(Ú<module>s     
;
a
A