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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
U
¬ý°d¤gã@s¦dZddlmZddlZddlmZddlmZddlZddl    m
Z
ddl m Z m Z mZmZmZmZmZddlZddlmZmZddlmmmZdd    lmZmZm Z m!Z!m"Z"dd
l#m$Z$dd l%m&Z&dd l'm(Z(dd l)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0ddl1m2Z2m3Z3ddl4m5Z5ddl6m7Z7ddl8m9Z9ddl:m;Z;ddl<m=Z=ddl>m?Z?ddl@mAmBZCddlDmEZEmFZFmGZGmHZHddlImJZJmKZKmLZLmMZMmNZNddlOmPZPddlQmRZRmSZSddlTmUZUmVZVddlWmXZXmYZYmZZZm[Z[m\Z\m]Z]m^Z^m_Z_m`Z`maZaddlbmcZcmdZdmeZee r8ddlfmgZgmhZhddlimjZjddlkmlZlGdd „d e?ƒZmGd!d"„d"emƒZnGd#d$„d$emƒZoGd%d&„d&emƒZpGd'd(„d(epƒZqeojeq_Gd)d*„d*eneqƒZrdS)+zc
Provide a generic structure to support window functions,
similar to how we have a Groupby object.
é)Ú annotationsN)Ú    timedelta)Úpartial)Údedent)Ú TYPE_CHECKINGÚAnyÚCallableÚHashableÚIteratorÚSizedÚcast)Ú
BaseOffsetÚ    to_offset)Ú    ArrayLikeÚAxisÚNDFrameTÚQuantileInterpolationÚWindowingRankType)Úimport_optional_dependency)Ú    DataError)Údoc)Úensure_float64Úis_boolÚ
is_integerÚ is_list_likeÚis_numeric_dtypeÚ    is_scalarÚneeds_i8_conversion)Ú ABCDataFrameÚ    ABCSeries)Únotna)Úexecutor)Ú    factorize)ÚResamplerWindowApply)ÚExtensionArray)ÚSelectionMixin)Ú BaseIndexerÚFixedWindowIndexerÚGroupbyIndexerÚVariableWindowIndexer)Ú DatetimeIndexÚIndexÚ
MultiIndexÚ PeriodIndexÚTimedeltaIndex)Úconcat)Úget_jit_argumentsÚmaybe_use_numba)Úflex_binary_momentÚzsqrt)
Ú _shared_docsÚcreate_section_headerÚkwargs_numeric_onlyÚ kwargs_scipyÚ numba_notesÚtemplate_headerÚtemplate_returnsÚtemplate_see_alsoÚwindow_agg_numba_parametersÚwindow_apply_parameters)Ú'generate_manual_numpy_nan_agg_with_axisÚgenerate_numba_apply_funcÚgenerate_numba_table_func)Ú    DataFrameÚSeries)ÚNDFrame©Ú BaseGrouperc @sÞeZdZUdZgZded<eƒZded<ded<dgdd œd ddddddddddœ
dd„Zddœdd„Z    dddddœdd„Z
dhdd dd!œd"d#„Z dd$dd%œd&d'„Z d(d(d)œd*d+„Z did(d$d(d,œd-d.„Zdjd/d0„Zdd1œd2d3„Zd4d5„Zddœd6d7„Zd8dœd9d:„Zd;dd<œd=d>„Zd?d?dd@œdAdB„ZedCdD„ƒZd?d?d?dEœdFdG„ZdHdœdIdJ„ZdkdKddLdMœdNdO„ZdldKdd$dPdQœdRdS„ZdmdKdd$dPdQœdTdU„ZdPdVddWd$dPdXœdYdZ„Zdnd\dd$d]d^œd_d`„Zdod\dadbœdcdd„Zdedf„Z e Z!dS)pÚ
BaseWindowz7Provides utilities for performing windowing operations.ú    list[str]Ú _attributeszfrozenset[Hashable]Ú
exclusionsr+Ú_onNFrÚsingle)Ú    selectionrCz
int | Noneú bool | Noneú
str | Nonerzstr | Index | NoneÚstrÚNone)
ÚobjÚ min_periodsÚcenterÚwin_typeÚaxisÚonÚclosedÚstepÚmethodÚreturnc  Csè||_||_||_|    |_||_||_||_||_|dk    rB| |¡nd|_    |
|_
d|_ |jdkr€|j    dkrt|jj |_ qÖ|jj|_ nVt|jtƒr–|j|_ n@t|jtƒrÄ|j|jjkrÄt|j|jƒ|_ ntd|j›dƒ‚| |_| ¡dS)Nrzinvalid on specified as z3, must be a column (of DataFrame), an Index or None)rQrVrWrXÚwindowrRrSrTZ_get_axis_numberrUrYÚ _win_freq_i8ÚindexrJÚcolumnsÚ
isinstancer+rÚ
ValueErrorZ
_selectionÚ    _validate) ÚselfrQr[rRrSrTrUrVrWrXrYrL©rcúQd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\pandas/core/window/rolling.pyÚ__init__us0
 
 
 ÿzBaseWindow.__init__©rZcCsX|jdk    rt|jƒstdƒ‚|jdk    rxt|jƒs8tdƒ‚|jdkrJtdƒ‚t|jƒrx|j|jkrxtd|j›d|j›ƒ‚|jdk    r”|jdkr”tdƒ‚t|jt    t
fƒs¶t d    t |ƒ›ƒ‚t|jt ƒr t |jj¡j ¡}t t ƒj¡j ¡}||kr tt |jƒj›d
ƒ‚|jd kr td ƒ‚|jdk    rTt|jƒs@td ƒ‚|jdkrTtdƒ‚dS)Nzcenter must be a booleanzmin_periods must be an integerrzmin_periods must be >= 0z min_periods z must be <= window )ÚrightZbothÚleftZneitherz3closed must be 'right', 'left', 'both' or 'neither'zinvalid type: z? does not implement the correct signature for get_window_bounds)ÚtablerKz!method must be 'table' or 'singlezstep must be an integerzstep must be >= 0)rSrr`rRrr[rWr_rQrrÚ    TypeErrorÚtyper&ÚinspectÚ    signatureÚget_window_boundsÚ
parametersÚkeysÚ__name__rYrX)rbZget_window_bounds_signatureZexpected_signaturercrcrdra¢sB
 
 
ÿÿ
ÿ
 
ÿ    zBaseWindow._validateú
np.ndarrayÚint)ÚstartÚendÚnum_valsrZcCsxt|ƒt|ƒkr.tdt|ƒ›dt|ƒ›dƒ‚t|ƒ||jp>dd|jpLdkrttdt|ƒ›d|›d|j›dƒ‚dS)    Nzstart (z ) and end (z ) bounds must be the same lengthézstart and end bounds (z)) must be the same length as the object (z) divided by the step (z) if given and rounded up)Úlenr`rX)rbrtrurvrcrcrdÚ_check_window_boundsÍsÿ$ÿzBaseWindow._check_window_boundsz Sized | None)r]ÚresultrZcCs,|dkst|ƒt|ƒkr|S|dd|j…S)zJ
        Slices the index for a given result and the preset step.
        N)rxrX)rbr]rzrcrcrdÚ_slice_axis_for_stepÜs ÿÿýzBaseWindow._slice_axis_for_stepÚbool)ÚnameÚ numeric_onlyrZcCs:|jjdkr6|r6t|jjƒs6tt|ƒj›d|›dƒ‚dS)zö
        Validate numeric_only argument, raising if invalid for the input.
 
        Parameters
        ----------
        name : str
            Name of the operator (kernel).
        numeric_only : bool
            Value passed by user.
        rwÚ.z  does not implement numeric_onlyN)Ú _selected_objÚndimrÚdtypeÚNotImplementedErrorrkrq)rbr}r~rcrcrdÚ_validate_numeric_onlyæs
ÿþ
ýÿz!BaseWindow._validate_numeric_onlyr)rQrZcCs|jdgdgd}|S)z¹Subset DataFrame to numeric columns.
 
        Parameters
        ----------
        obj : DataFrame
 
        Returns
        -------
        obj subset to numeric-only columns.
        Únumberr)ÚincludeÚexclude)Z select_dtypes)rbrQrzrcrcrdÚ_make_numeric_onlyús zBaseWindow._make_numeric_only©rQr~rZcCs„|jdk    r:t|jtƒs:|jdkr:|j|j |jg¡dd}|jdkr\|sR|jdkr\| |¡}|jdkr€|j    ddd}|j
  ¡|_
|S)úA
        Split data into blocks & return conformed data.
        NéF)r^ÚcopyrwÚfloat64)rŒ) rVr_r+rÚreindexr^Ú
differencerUrˆÚastypeÚ_mgrÚ consolidate)rbrQr~rcrcrdÚ _create_datas 
 
 zBaseWindow._create_datacsŠ|dkrˆj}‡fdd„ˆjDƒ}d}|jdkrNt|ƒr@||ksHt|ƒrN|}n |jdkrnt|ƒrn||jkrn|}tˆƒ|fd|i|—Ž}|S)a 
        Sub-classes to define. Return a sliced object.
 
        Parameters
        ----------
        key : str / list of selections
        ndim : {1, 2}
            requested ndim of result
        subset : object, default None
            subset to act on
        Ncsi|]}|tˆ|ƒ“qSrc©Úgetattr)Ú.0Úattr©rbrcrdÚ
<dictcomp>+sz'BaseWindow._gotitem.<locals>.<dictcomp>r‹rwrL)rQrHrrrr}rk)rbÚkeyrÚsubsetÚkwargsrLZnew_winrcr˜rdÚ_gotitems  
ÿÿÿzBaseWindow._gotitem)r—cCsH||jkrt ||¡S||jkr(||Stdt|ƒj›d|›dƒ‚dS)Nú'z' object has no attribute ')Z_internal_names_setÚobjectÚ__getattribute__rQÚAttributeErrorrkrq)rbr—rcrcrdÚ __getattr__8s
 
ÿzBaseWindow.__getattr__cCs
|j ¡S©N)rQÚ_dir_additionsr˜rcrcrdr¤BszBaseWindow._dir_additionscs4‡fdd„ˆjDƒ}d |¡}tˆƒj›d|›dS)z@
        Provide a nice str repr of our rolling object.
        c3s>|]6}tˆ|dƒdk    r|ddkr|›dtˆ|ƒ›VqdS)NrÚ_ú=r”)r–Ú    attr_namer˜rcrdÚ    <genexpr>Is þz&BaseWindow.__repr__.<locals>.<genexpr>ú,z [ú])rHÚjoinrkrq)rbZ
attrs_listÚattrsrcr˜rdÚ__repr__Es
 
þ
zBaseWindow.__repr__r
ccs„|j |j¡}| |¡}| ¡}|jt|ƒ|j|j|j    |j
d\}}|  ||t|ƒ¡t ||ƒD]\}}|j t||ƒ}|Vq`dS©N©Z
num_valuesrRrSrWrX)r€Zset_axisrJr“Ú_get_window_indexerrnrxrRrSrWrXryÚzipZilocÚslice)rbrQÚindexerrtruÚsÚerzrcrcrdÚ__iter__Qs
û
zBaseWindow.__iter__r)ÚvaluesrZc
Cs²t|jƒr(tdt|ƒj›d|j›dƒ‚z*t|tƒrH|jtj    tj
d}nt |ƒ}Wn8t t fk
rŠ}zt d|j›ƒ|‚W5d}~XYnXt |¡}| ¡r®t |tj
|¡}|S)z1Convert input to numpy arrays for Cython routineszops for z for this dtype z are not implemented)Zna_valuezcannot handle this type -> N)rr‚rƒrkrqr_r$Úto_numpyÚnprÚnanrr`rjÚisinfÚanyÚwhere)rbr·ÚerrÚinfrcrcrdÚ _prep_valuescs
ÿ
 $
zBaseWindow._prep_valuesrA)rzrQrZc Cs¾ddlm}|jdk    rº|j |j¡sº|jj}||j|jj|dd}||jkrV|||<nd||jj    krdnV||j
jkr²|j
j}|j}|  |¡}|  |d|…¡}    t |    ƒ}
| |
||¡n|||<dS)Nr©rBF©r]r}rŒ)ÚpandasrBrVrJÚequalsr]r}rQr^Únamesr€Zget_locÚ intersectionrxÚinsert) rbrzrQrBr}Z    extra_colZold_colsZnew_colsZold_locÚoverlapZnew_locrcrcrdÚ_insert_on_column{s  
 
 
zBaseWindow._insert_on_columncCs"t|jjƒrtd|jƒ}|jSdS)Nz,PeriodIndex | DatetimeIndex | TimedeltaIndex)rrJr‚r Zasi8)rbÚidxrcrcrdÚ _index_array”s  zBaseWindow._index_array)ÚoutrQrZcCsL|jddkr$|jddkr$tdƒ‚|jddkr<| d¡S| ||¡|S)zValidate and finalize result.rwrúNo numeric types to aggregater)ÚshaperrrÉ)rbrÌrQrcrcrdÚ_resolve_outputœs 
 zBaseWindow._resolve_outputr&cCs<t|jtƒr|jS|jdk    r0t|j|j|jdSt|jdS)z[
        Return an indexer class that will compute the window start and end bounds
        N)Ú index_arrayÚ window_sizerS)rÑ)r_r[r&r\r)rËrSr'r˜rcrcrdr°¦s 
ýzBaseWindow._get_window_indexerzCallable[..., ArrayLike]rB)Úhomogeneous_funcr}rZc
CsŒ| |j¡}|dkr"t|ƒ t¡}z| |j¡}Wn0ttfk
rb}zt    dƒ|‚W5d}~XYnX||ƒ}| 
|j |¡}|j |||j dS)z4
        Series version of _apply_blockwise
        ÚcountrÍN©r]r})r“r€r rrsrÀZ_valuesrjrƒrr{r]Ú _constructorr})rbrÒr}rQr·r¾rzr]rcrcrdÚ _apply_series´s zBaseWindow._apply_seriesúDataFrame | Series)rÒr}r~rZc CsF| ||¡|jjdkr$| ||¡S| |j|¡}|dkrTt|ƒ t¡}|j     ¡|_|j
dkrd|j }g}g}t |  ¡ƒD]l\}}z| |¡}Wn8ttfk
rÆ}    ztd|j›ƒ|    ‚W5d}    ~    XYnX||ƒ}
| |
¡| |¡qx| |jt|ƒdkr|dnd¡} t|ƒj|| |j |¡dd} |j
dkr:| j } | | |¡S)zl
        Apply the given function to the DataFrame broken down into homogeneous
        sub-frames.
        rwrÓz#Cannot aggregate non-numeric type: NrF)r]r^Úverify_integrity)r„r€rrÖr“r rrsr‘r’rUÚTÚ    enumerateZ_iter_column_arraysrÀrjrƒrr‚Úappendr{r]rxrkZ _from_arraysr^ÚtakerÏ) rbrÒr}r~rQZtakerZ
res_valuesÚiZarrr¾Úresr]ZdfrcrcrdÚ_apply_blockwiseÈsH
 
 
ÿþ
 ÿ
ü zBaseWindow._apply_blockwisec
Cs¶|jjdkrtdƒ‚| |j|¡}| | ¡¡}|jdkr@|jn|}||ƒ}|jdkr\|jn|}| |j    |¡}|j
dt |j ƒkrˆ|j n|j dd|j …}|j|||d}    | |    |¡S)zT
        Apply the given function to the DataFrame across the entire object
        rwz1method='table' not applicable for Series objects.N©r]r^)r€rr`r“rÀr¸rUrÙr{r]rÎrxr^rXrÕrÏ)
rbrÒr}r~rQr·rzr]r^rÌrcrcrdÚ_apply_tablewiseýs     ÿýzBaseWindow._apply_tablewiseúDataFrame | Series | NoneúFCallable[[DataFrame | Series, DataFrame | Series], DataFrame | Series]©ÚtargetÚotherÚpairwiseÚfuncr~rZcCsn| ||¡}|dkr*|}|dkr$dn|}n0t|ttfƒsBtdƒ‚n|jdkrZ|rZ| |¡}t|||t|ƒdS)ú]
        Apply the given pairwise function given 2 pandas objects (DataFrame/Series)
        NTz#other must be a DataFrame or Seriesr‹)rç)    r“r_rrr`rrˆr2r|)rbrårærçrèr~rcrcrdÚ_apply_pairwises 
 
zBaseWindow._apply_pairwisercúCallable[..., Any]útuple[Any, ...]©rèr}r~Ú
numba_argsc sbˆ ¡‰ˆjdk    rˆjnˆj‰ddœ‡‡‡‡‡fdd„ }ˆjdkrPˆ |||¡Sˆ |||¡SdS)aÞ
        Rolling statistical measure using supplied function.
 
        Designed to be used with passed-in Cython array-based functions.
 
        Parameters
        ----------
        func : callable function to apply
        name : str,
        numba_args : tuple
            args to be passed when func is a numba func
        **kwargs
            additional arguments for rolling function and window function
 
        Returns
        -------
        y : type of input
        Nrr©r·c    sJ|jdkr| ¡S‡‡‡‡‡fdd„}tjdd||ƒ}W5QRX|S)NrcsHˆjt|ƒˆˆjˆjˆjd\}}ˆ ||t|ƒ¡ˆ|||ˆfˆžŽSr®)rnrxrSrWrXry)Úxrtru©rèrRrîrbÚwindow_indexerrcrdÚcalcUsû
z9BaseWindow._apply.<locals>.homogeneous_func.<locals>.calcÚignore©Úall)ÚsizerŒr¹Úerrstate©r·rórzrñrcrdrÒOs 
 z+BaseWindow._apply.<locals>.homogeneous_funcrK)r°rRrÑrYrßrá©rbrèr}r~rîrœrÒrcrñrdÚ_apply.sÿý
zBaseWindow._applyúdict[str, bool] | None)rèÚ engine_kwargscGs4| ¡}|jdk    r|jn|j}| |j¡}|jdkr:|j}| | ¡¡}|j    dkr^| 
dd¡}|j t |ƒ||j |j|jd\}}    | ||    t |ƒ¡tj|ft|ƒŽ}
|
|||    |f|žŽ} |jdkrÈ| jn| } | |j| ¡} |j    dkr|  ¡} |j| | |jd} | S| |j| j¡}|j| | |d} | | |¡SdS)Nrwéÿÿÿÿr¯rÔrà)r°rRrÑr“r€rUrÙrÀr¸rZreshapernrxrSrWrXryr!Zgenerate_shared_aggregatorr0r{r]ZsqueezerÕr}r^rÏ)rbrèrýÚ    func_argsròrRrQr·rtruZ
aggregatorrzr]rÌr^rcrcrdÚ _numba_applyksDÿý 
 
 û
ÿÿ zBaseWindow._numba_applycOs2t||||d ¡}|dkr.|j|d||dS|S)N©ÚargsrœF)Úrawrrœ)r#ÚaggÚapply©rbrèrrœrzrcrcrdÚ    aggregate”szBaseWindow.aggregate)    NNFNrNNNrK)N)F)N)N)F)NF)Frc)N)"rqÚ
__module__Ú __qualname__Ú__doc__rHÚ__annotations__Ú    frozensetrIreraryr{r„rˆr“rr¢r¤r­r¶rÀrÉÚpropertyrËrÏr°rÖrßrárêrûrrrrcrcrcrdrFns`
 õ ó$-+
 
 
 
 
ÿü8üû@ý)rFcs°eZdZUdZded<ded<dgZded<dd    œd
ddd d œ‡fd d„Zd$ddddd
dœ‡fdd„ Zd
ddddd
dœ‡fdd„ Zd%ddddœ‡fdd „ Z    d&‡fd"d#„    Z
‡Z S)'ÚBaseWindowGroupbyz3
    Provide the groupby windowing facilities.
    rEÚ_grouperr|Ú    _as_indexrGrHT)rr×rP)rQrrrZcsjddlm}t||ƒstdƒ‚||_||_|j|jjdd}| d¡dk    rRt    dƒ‚t
ƒj |f|ž|ŽdS)NrrDzMust pass a BaseGrouper object.rô©r^ÚerrorsrXz step not implemented for groupby) Úpandas.core.groupby.opsrEr_r`rrÚdroprÅÚgetrƒÚsuperre)rbrQrrrrœrE©Ú    __class__rcrdre¦s 
zBaseWindowGroupby.__init__FrcrërOrì)rèr}r~rîrZc sLtƒj||||f|Ž}ˆjj}|j•}t ˆjj¡}    |    |}
‡fdd„ˆjjDƒ} t| ƒt|    ƒkrp|j| dd}ˆjj    } t ˆjj
¡} ˆjj   ¡}|r¦t  t|ƒ¡‰nt jgt jd‰‡fdd„| Dƒ} |dk    r| ˆ¡}t|tƒsòt |g¡}|  t|j    ƒ¡|  t|j
ƒ¡t| | |
dd}||_ˆjsH|jttt|    ƒƒƒd    }|S)
Ncs&g|]}|ˆjjjks|dkr|‘qSr£)rQr]rÅ)r–ršr˜rcrdÚ
<listcomp>Ôsþz,BaseWindowGroupby._apply.<locals>.<listcomp>rôr©r‚csg|]}| ˆ¡‘qSrc)rÜ©r–Úc)r³rcrdræsF©rÅrØ)Úlevel)rrûrQr]rÅrŒrrxrÚcodesÚlevelsÚindicesr·r¹Ú concatenateÚlistÚarrayÚintprÜr_r,Z from_arraysÚextendrZ reset_indexÚrange)rbrèr}r~rîrœrzZgrouped_object_indexZgrouped_index_nameZ groupby_keysZresult_index_namesZ drop_columnsrr Ú group_indicesrÊÚ result_indexr)r³rbrdrû½sPüû
 
þ 
 
 
 ÿzBaseWindowGroupby._applyrârMrãräcsØ|j|jjdd}tƒ |ˆ|||¡‰ˆdk    rØt‡fdd„|jj ¡DƒƒsØtˆƒ}t    ‡fdd„|jj ¡Dƒƒ‰dd„|jj 
¡Dƒ}g}g}    t t t |ŽƒD]6}
t t |
¡|¡} t| ƒ\} } | | ¡|     | ¡qžnr|jj}|jj}    |jj ¡}|r
t t |ƒ¡‰ntjgtjd    ‰|jd
kr,d
‰n
t|jƒ‰‡‡fd d„|Dƒ}tˆjtƒr~t ˆjjƒ}t ˆjjƒ}t ˆjjƒ}n$tˆjƒ\}}|g}|g}ˆjjg}||}|    |}|jj|}t|||d d }|ˆ_ˆS)rérôrNc3s|]}t|ƒtˆƒkVqdSr£)rx)r–Úgroup)rærcrdr¨    sz4BaseWindowGroupby._apply_pairwise.<locals>.<genexpr>csg|]}ˆ |¡ ˆj¡‘qSrc)rÜrŽr])r–Z
gb_indices)rzrcrdrsÿz5BaseWindowGroupby._apply_pairwise.<locals>.<listcomp>css|]}t |¡VqdSr£)ÚcomZmaybe_make_list)r–Úpairrcrcrdr¨srrwcsg|]}t | ˆ¡ˆ¡‘qSrc)r¹ÚrepeatrÜr)r³Ú    repeat_byrcrdr5sFr)rrrÅrrêrör!r·rxr/rpÚmapr#r±r¹r-r$r"rÛrr r"r%rr^r_r]r,r})rbrårærçrèr~Zold_result_lenZgb_pairsZ groupby_codesZgroupby_levelsZ gb_level_pairÚlabelsrr r(Z result_codesZ result_levelsZ result_namesZ    idx_codesZ
idx_levelsr)r)r³rær.rzrdrêúsh 
ÿ
 
þÿ
ÿ 
 
 ÿ  
 ÿz!BaseWindowGroupby._apply_pairwiserr‰cs<|js.t t|jj ¡ƒ¡ tj¡}|     |¡}t
ƒ  ||¡S)rŠ) Úemptyr¹r"r#rr!r·rÚint64rÜrr“)rbrQr~Z groupby_orderrrcrdr“Ns ÿ
zBaseWindowGroupby._create_dataNcs*|jdk    r|j |j¡}tƒj|||dS)N)r›)rVrQZ    set_indexrJrr)rbršrr›rrcrdr\s
zBaseWindowGroupby._gotitem)Frc)F)N) rqrr    r
r rHrerûrêr“rÚ __classcell__rcrcrrdrs
ûû=Trc s”eZdZdZdddddddd    d
g    Z‡fd d „Zd dd dœdd„Zd=dddddœdd„Zee    de
dƒe
dƒddd d!d"„ƒZ e Z ee ed#ƒeeed$ƒeed%ƒed&d'…d(d)d*d+ d>dd,œd-d.„ƒZee ed#ƒeeed$ƒeed%ƒed&d'…d(d/d0d+ d?dd,œd1d2„ƒZee ed#ƒeeed$ƒeed%ƒed&d'…d(d3d4d+ d@ddd6œd7d8„ƒZee ed#ƒeeed$ƒeed%ƒed&d'…d(d9d:d+ dAddd6œd;d<„ƒZ‡ZS)BÚWindowa
    Provide rolling window calculations.
 
    Parameters
    ----------
    window : int, timedelta, str, offset, or BaseIndexer subclass
        Size of the moving window.
 
        If an integer, the fixed number of observations used for
        each window.
 
        If a timedelta, str, or offset, the time period of each window. Each
        window will be a variable sized based on the observations included in
        the time-period. This is only valid for datetimelike indexes.
        To learn more about the offsets & frequency strings, please see `this link
        <https://pandas.pydata.org/pandas-docs/stable/user_guide/timeseries.html#offset-aliases>`__.
 
        If a BaseIndexer subclass, the window boundaries
        based on the defined ``get_window_bounds`` method. Additional rolling
        keyword arguments, namely ``min_periods``, ``center``, ``closed`` and
        ``step`` will be passed to ``get_window_bounds``.
 
    min_periods : int, default None
        Minimum number of observations in window required to have a value;
        otherwise, result is ``np.nan``.
 
        For a window that is specified by an offset, ``min_periods`` will default to 1.
 
        For a window that is specified by an integer, ``min_periods`` will default
        to the size of the window.
 
    center : bool, default False
        If False, set the window labels as the right edge of the window index.
 
        If True, set the window labels as the center of the window index.
 
    win_type : str, default None
        If ``None``, all points are evenly weighted.
 
        If a string, it must be a valid `scipy.signal window function
        <https://docs.scipy.org/doc/scipy/reference/signal.windows.html#module-scipy.signal.windows>`__.
 
        Certain Scipy window types require additional parameters to be passed
        in the aggregation function. The additional parameters must match
        the keywords specified in the Scipy window type method signature.
 
    on : str, optional
        For a DataFrame, a column label or Index level on which
        to calculate the rolling window, rather than the DataFrame's index.
 
        Provided integer column is ignored and excluded from result since
        an integer index is not used to calculate the rolling window.
 
    axis : int or str, default 0
        If ``0`` or ``'index'``, roll across the rows.
 
        If ``1`` or ``'columns'``, roll across the columns.
 
        For `Series` this parameter is unused and defaults to 0.
 
    closed : str, default None
        If ``'right'``, the first point in the window is excluded from calculations.
 
        If ``'left'``, the last point in the window is excluded from calculations.
 
        If ``'both'``, the no points in the window are excluded from calculations.
 
        If ``'neither'``, the first and last points in the window are excluded
        from calculations.
 
        Default ``None`` (``'right'``).
 
        .. versionchanged:: 1.2.0
 
            The closed parameter with fixed windows is now supported.
 
    step : int, default None
 
        .. versionadded:: 1.5.0
 
        Evaluate the window at every ``step`` result, equivalent to slicing as
        ``[::step]``. ``window`` must be an integer. Using a step argument other
        than None or 1 will produce a result with a different shape than the input.
 
    method : str {'single', 'table'}, default 'single'
 
        .. versionadded:: 1.3.0
 
        Execute the rolling operation per single column or row (``'single'``)
        or over the entire object (``'table'``).
 
        This argument is only implemented when specifying ``engine='numba'``
        in the method call.
 
    Returns
    -------
    ``Window`` subclass if a ``win_type`` is passed
 
    ``Rolling`` subclass if ``win_type`` is not passed
 
    See Also
    --------
    expanding : Provides expanding transformations.
    ewm : Provides exponential weighted functions.
 
    Notes
    -----
    See :ref:`Windowing Operations <window.generic>` for further usage details
    and examples.
 
    Examples
    --------
    >>> df = pd.DataFrame({'B': [0, 1, 2, np.nan, 4]})
    >>> df
         B
    0  0.0
    1  1.0
    2  2.0
    3  NaN
    4  4.0
 
    **window**
 
    Rolling sum with a window length of 2 observations.
 
    >>> df.rolling(2).sum()
         B
    0  NaN
    1  1.0
    2  3.0
    3  NaN
    4  NaN
 
    Rolling sum with a window span of 2 seconds.
 
    >>> df_time = pd.DataFrame({'B': [0, 1, 2, np.nan, 4]},
    ...                        index = [pd.Timestamp('20130101 09:00:00'),
    ...                                 pd.Timestamp('20130101 09:00:02'),
    ...                                 pd.Timestamp('20130101 09:00:03'),
    ...                                 pd.Timestamp('20130101 09:00:05'),
    ...                                 pd.Timestamp('20130101 09:00:06')])
 
    >>> df_time
                           B
    2013-01-01 09:00:00  0.0
    2013-01-01 09:00:02  1.0
    2013-01-01 09:00:03  2.0
    2013-01-01 09:00:05  NaN
    2013-01-01 09:00:06  4.0
 
    >>> df_time.rolling('2s').sum()
                           B
    2013-01-01 09:00:00  0.0
    2013-01-01 09:00:02  1.0
    2013-01-01 09:00:03  3.0
    2013-01-01 09:00:05  NaN
    2013-01-01 09:00:06  4.0
 
    Rolling sum with forward looking windows with 2 observations.
 
    >>> indexer = pd.api.indexers.FixedForwardWindowIndexer(window_size=2)
    >>> df.rolling(window=indexer, min_periods=1).sum()
         B
    0  1.0
    1  3.0
    2  2.0
    3  4.0
    4  4.0
 
    **min_periods**
 
    Rolling sum with a window length of 2 observations, but only needs a minimum of 1
    observation to calculate a value.
 
    >>> df.rolling(2, min_periods=1).sum()
         B
    0  0.0
    1  1.0
    2  3.0
    3  2.0
    4  4.0
 
    **center**
 
    Rolling sum with the result assigned to the center of the window index.
 
    >>> df.rolling(3, min_periods=1, center=True).sum()
         B
    0  1.0
    1  3.0
    2  3.0
    3  6.0
    4  4.0
 
    >>> df.rolling(3, min_periods=1, center=False).sum()
         B
    0  0.0
    1  1.0
    2  3.0
    3  3.0
    4  6.0
 
    **step**
 
    Rolling sum with a window length of 2 observations, minimum of 1 observation to
    calculate a value, and a step of 2.
 
    >>> df.rolling(2, min_periods=1, step=2).sum()
         B
    0  0.0
    2  3.0
    4  4.0
 
    **win_type**
 
    Rolling sum with a window length of 2, using the Scipy ``'gaussian'``
    window type. ``std`` is required in the aggregation function.
 
    >>> df.rolling(2, win_type='gaussian').sum(std=3)
              B
    0       NaN
    1  0.986207
    2  2.958621
    3       NaN
    4       NaN
 
    **on**
 
    Rolling sum with a window length of 2 days.
 
    >>> df = pd.DataFrame({
    ...     'A': [pd.to_datetime('2020-01-01'),
    ...           pd.to_datetime('2020-01-01'),
    ...           pd.to_datetime('2020-01-02'),],
    ...     'B': [1, 2, 3], },
    ...     index=pd.date_range('2020', periods=3))
 
    >>> df
                        A  B
    2020-01-01 2020-01-01  1
    2020-01-02 2020-01-01  2
    2020-01-03 2020-01-02  3
 
    >>> df.rolling('2D', on='A').sum()
                        A    B
    2020-01-01 2020-01-01  1.0
    2020-01-02 2020-01-01  3.0
    2020-01-03 2020-01-02  6.0
    r[rRrSrTrUrVrWrXrYcs¢tƒ ¡t|jtƒs&td|j›ƒ‚tddd}t||jdƒ|_|jdkr\td|j›ƒ‚t|j    t
ƒrpt dƒ‚t |j    ƒr„|j    dkrŒtdƒ‚|j dkržt d    ƒ‚dS)
NzInvalid win_type z scipy.signalz,Scipy is required to generate window weight.)Úextraz6BaseIndexer subclasses not implemented with win_types.rú&window must be an integer 0 or greaterrKz+'single' is the only supported method type.)rrar_rTrOr`rr•Ú_scipy_weight_generatorr[r&rƒrrY)rbÚsignalrrcrdrams$
 ÿ
 ÿ
zWindow._validaterrrs)rzÚoffsetrZcCs*|dkr&t|dƒg}t |t|ƒ¡}|S)zT
        Center the result in the window for weighted rolling aggregations.
        rN)r²r¹rŒÚtuple)rbrzr9Z lead_indexerrcrcrdÚ_center_windowƒs zWindow._center_windowFrcz,Callable[[np.ndarray, int, int], np.ndarray]rOr|rìríc s\ˆjˆjf|މˆjr&tˆƒddnd‰ddœ‡‡‡‡fdd„ }ˆ |||¡ddˆj…S)    a+
        Rolling with weights statistical measure using supplied function.
 
        Designed to be used with passed-in Cython array-based functions.
 
        Parameters
        ----------
        func : callable function to apply
        name : str,
        numeric_only : bool, default False
            Whether to only operate on bool, int, and float columns
        numba_args : tuple
            unused
        **kwargs
            additional arguments for scipy windows if necessary
 
        Returns
        -------
        y : type of input
        rwr‹rrrrïc    s`|jdkr| ¡S‡‡‡‡fdd„}tjddt ||ƒ¡}W5QRXˆjr\ˆ |ˆ¡}|S)Nrcs6t tjgˆ¡}t ||f¡}ˆ|ˆˆjp2tˆƒƒSr£)r¹r$rºr"rRrx)rðZadditional_nans©rèr9rbr[rcrdró´sz5Window._apply.<locals>.homogeneous_func.<locals>.calcrôrõ)r÷rŒr¹røZasarrayrSr;rùr<rcrdrÒ®s
 z'Window._apply.<locals>.homogeneous_funcN)r7r[rSrxrßrXrúrcr<rdrûŒsÿÿz Window._applyrz£
        See Also
        --------
        pandas.DataFrame.aggregate : Similar DataFrame method.
        pandas.Series.aggregate : Similar Series method.
        at
        Examples
        --------
        >>> df = pd.DataFrame({"A": [1, 2, 3], "B": [4, 5, 6], "C": [7, 8, 9]})
        >>> df
           A  B  C
        0  1  4  7
        1  2  5  8
        2  3  6  9
 
        >>> df.rolling(2, win_type="boxcar").agg("mean")
             A    B    C
        0  NaN  NaN  NaN
        1  1.5  4.5  7.5
        2  2.5  5.5  8.5
        zSeries/DataFrameÚ©Zsee_alsoZexamplesÚklassrUcOs(t||||d ¡}|dkr$||ƒ}|S)Nr)r#rrrcrcrdrÄs zWindow.aggregateÚ
ParametersÚReturnsúSee AlsoNrþÚrollingzweighted window sumÚsum©Z window_methodZaggregation_descriptionZ
agg_method©r~cKstj}|j|fd|dœ|—ŽS)NrD©r}r~)Úwindow_aggregationsZroll_weighted_sumrû©rbr~rœÚ window_funcrcrcrdrDísÿýüz
Window.sumzweighted window meanÚmeancKstj}|j|fd|dœ|—ŽS)NrKrG)rHZroll_weighted_meanrûrIrcrcrdrKsÿýüz Window.meanzweighted window varianceÚvarrw©Úddofr~cKs2ttj|d}| dd¡|j|fd|dœ|—ŽS)N©rNr}rLrG)rrHZroll_weighted_varÚpoprû)rbrNr~rœrJrcrcrdrLs z
Window.varz"weighted window standard deviationÚstdcKst|jf|d|dœ|—ŽƒS)NrQ)rNr}r~)r3rL)rbrNr~rœrcrcrdrQ1sÿz
Window.std)Frc)F)F)rwF)rwF)rqrr    r
rHrar;rûrr4rrrr9r5r6r7r:r;rDrKrLrQr3rcrcrrdr4fs¬|÷  û8ÿÿã
 
õ  
õ  
õ 
õ r4c@sdeZdZdAddœdd„ZdBdddd    d
d d œd d„Zddddddœdd„ZdCddd    dœdd„ZdDddd    dœdd„ZdEddd    dœdd„ZdFddd    dœdd„Z    dGddd    dœdd„Z
dHd!ddd    d"œd#d$„Z dId!ddd    d"œd%d&„Z dJddœd'd(„Z dKd!dd)œd*d+„ZdLddœd,d-„ZdMd/d0dd1œd2d3„ZdNd6dddd7œd8d9„ZdOd:d;d!dd<œd=d>„ZdPd:d;d!dd<œd?d@„ZdS)QÚRollingAndExpandingMixinFr|rFcCstj}|j|d|dS)NrÓrG)rHÚroll_sumrû©rbr~rJrcrcrdrÓEszRollingAndExpandingMixin.countNrërNrüútuple[Any, ...] | Noneúdict[str, Any] | None©rèrÚenginerýrrœc    Cs¼|dkr d}|dkri}t|ƒs(tdƒ‚d}t|ƒrz|dkrDtdƒ‚|}|jdkrft|ft||ƒŽ}q¬t|ft||ƒŽ}n2|dkr¤|dk    r’tdƒ‚| ||||¡}ntdƒ‚|j|d    |d
S) Nrcz'raw parameter must be `True` or `False`Fz.raw must be `True` when using the numba enginerK)ZcythonNz+cython engine does not accept engine_kwargsz)engine must be either 'numba' or 'cython'r)r}rî)    rr`r1rYr?r0r@Ú_generate_cython_apply_funcrû)    rbrèrrXrýrrœrîÚ
apply_funcrcrcrdrIs@    
ÿÿÿÿýzRollingAndExpandingMixin.applyrìzdict[str, Any]z?Callable[[np.ndarray, np.ndarray, np.ndarray, int], np.ndarray])rrœrÚfunctionrZcs8ddlm‰ttj||||d‰|f‡‡‡fdd„    }|S)NrrÁ)rrœrr[cs"|sˆ|ˆjdd}ˆ||||ƒS)NF)r]rŒ)rJ)r·ÚbeginrurRr©rBrbrJrcrdrZ…szHRollingAndExpandingMixin._generate_cython_apply_func.<locals>.apply_func)rÃrBrrHZ
roll_apply)rbrrœrr[rZrcr]rdrYts ûz4RollingAndExpandingMixin._generate_cython_apply_func©r~rXrýcCs\t|ƒrF|jdkr.ttjƒ}|j|d||dSddlm}| ||¡St    j
}|j |d|dS)NriT©rrXrýr)Ú sliding_sumrDrG) r1rYr>r¹ZnansumrÚpandas.core._numba.kernelsr`rrHrSrû)rbr~rXrýrèr`rJrcrcrdrDs
 
ü  zRollingAndExpandingMixin.sumcCs^t|ƒrH|jdkr.ttjƒ}|j|d||dSddlm}| ||d¡St    j
}|j |d|dS)NriTr_r©Úsliding_min_maxÚmaxrG) r1rYr>r¹ZnanmaxrrarcrrHÚroll_maxrû©rbr~rXrýrèrcrJrcrcrdrd£s
 
ü zRollingAndExpandingMixin.maxcCs^t|ƒrH|jdkr.ttjƒ}|j|d||dSddlm}| ||d¡St    j
}|j |d|dS)    NriTr_rrbFÚminrG) r1rYr>r¹ZnanminrrarcrrHÚroll_minrûrfrcrcrdrg¹s
 
ü zRollingAndExpandingMixin.mincCs\t|ƒrF|jdkr.ttjƒ}|j|d||dSddlm}| ||¡St    j
}|j |d|dS)NriTr_r)Ú sliding_meanrKrG) r1rYr>r¹ZnanmeanrrarirrHÚ    roll_meanrû)rbr~rXrýrèrirJrcrcrdrKÏs
 
ü  zRollingAndExpandingMixin.meancCsLt|ƒr6|jdkrttjƒ}ntj}|j|d||dStj}|j|d|dS)NriTr_ÚmedianrG)    r1rYr>r¹Z    nanmedianrrHZ roll_median_crû)rbr~rXrýrèrJrcrcrdrkås
 üzRollingAndExpandingMixin.medianrwrs©rNr~rXrýcs\t|ƒr8|jdkrtdƒ‚ddlm}t| ||ˆ¡ƒStj‰‡‡fdd„}|j    |d|dS)    Nriz%std not supported with method='table'r©Ú sliding_varcstˆ||||ˆdƒS)NrO)r3)r·r\rurR©rNrJrcrdÚ
zsqrt_func    sz0RollingAndExpandingMixin.std.<locals>.zsqrt_funcrQrG)
r1rYrƒrarnr3rrHÚroll_varrû)rbrNr~rXrýrnrprcrordrQús
 ýzRollingAndExpandingMixin.stdcCsRt|ƒr4|jdkrtdƒ‚ddlm}| |||¡Sttj|d}|j    |d|dS)Nriz%var not supported with method='table'rrmrOrLrG)
r1rYrƒrarnrrrHrqrû)rbrNr~rXrýrnrJrcrcrdrLs
 ýzRollingAndExpandingMixin.varcCstj}|j|d|dS)NÚskewrG)rHZ    roll_skewrûrTrcrcrdrr&s ýzRollingAndExpandingMixin.skewrMcCs.| d|¡|j|d|j|d| d¡S©NÚsemrFçà?©r„rQrÓÚpow©rbrNr~rcrcrdrt.s  
ÿþzRollingAndExpandingMixin.semcCstj}|j|d|dS)NÚkurtrG)rHZ    roll_kurtrûrTrcrcrdry5s ýzRollingAndExpandingMixin.kurtÚlinearÚfloatr©ÚquantileÚ interpolationr~cCs@|dkrtj}n |dkr tj}nttj||d}|j|d|dS)Ngð?g)r}r~r}rG)rHrerhrZ roll_quantilerû)rbr}r~r~rJrcrcrdr}=sýz!RollingAndExpandingMixin.quantileÚaverageTr©rYÚ    ascendingÚpctr~cCs"ttj|||d}|j|d|dS)N)rYrZ
percentileÚrankrG)rrHZ    roll_rankrû)rbrYrr‚r~rJrcrcrdrƒPsüzRollingAndExpandingMixin.rankrârM©rærçrNr~csNˆjdk    rtdƒ‚ˆ d|¡ddlm‰‡‡‡fdd„}ˆ ˆj||||¡S)Nzstep not implemented for covÚcovrrÁc     sþˆ |¡}ˆ |¡}ˆ ¡}ˆjdk    r,ˆjn|j}|jt|ƒ|ˆjˆjˆjd\}}ˆ     ||t|ƒ¡t
j ddrt   |||||¡}t   ||||¡}    t   ||||¡}
t  t||ƒ t
j¡||d¡} ||    |
| | ˆ} W5QRXˆ| |j|jddS)Nr¯rôrõrFrÂ)rÀr°rRrÑrnrxrSrWrXryr¹rørHrjrSr rrr]r}) rðÚyÚx_arrayÚy_arrayròrRrtruÚmean_x_yÚmean_xÚmean_yÚ    count_x_yrz©rBrNrbrcrdÚcov_funcms@
 
ÿýû
ÿÿ"z.RollingAndExpandingMixin.cov.<locals>.cov_func©rXrƒr„rÃrBrêr€)rbrærçrNr~rŽrcrrdr…`s
  ÿzRollingAndExpandingMixin.covcsNˆjdk    rtdƒ‚ˆ d|¡ddlm‰‡‡‡fdd„}ˆ ˆj||||¡S)Nzstep not implemented for corrÚcorrrrÁc    s6ˆ |¡}ˆ |¡}ˆ ¡}ˆjdk    r,ˆjn|j}|jt|ƒ|ˆjˆjˆjd\}}ˆ     ||t|ƒ¡t
j ddªt   |||||¡}t   ||||¡}    t   ||||¡}
t  t||ƒ t
j¡||d¡} t  ||||ˆ¡} t  ||||ˆ¡} ||    |
| | ˆ}| | d}||}W5QRXˆ||j|jddS)Nr¯rôrõrruFrÂ)rÀr°rRrÑrnrxrSrWrXryr¹rørHrjrSr rrrqr]r})rðr†r‡rˆròrRrtrur‰rŠr‹rŒZx_varZy_varÚ    numeratorÚ denominatorrzrrcrdÚ    corr_funcœsd
 
ÿýû
ÿÿÿÿ
 
ÿ z0RollingAndExpandingMixin.corr.<locals>.corr_funcr)rbrærçrNr~r“rcrrdrs
  (ÿzRollingAndExpandingMixin.corr)F)FNNNN)FNN)FNN)FNN)FNN)FNN)rwFNN)rwFNN)F)rwF)F)rzF)rTFF)NNrwF)NNrwF)rqrr    rÓrrYrDrdrgrKrkrQrLrrrtryr}rƒr…rrcrcrcrdrRDsvù+üüüüüûû üûû1ûrRcsØeZdZUddddddddd    g    Zd
ed <‡fd d „Zddœdd„Zddœdd„Zee    de
dƒe
dƒddd‡fdd„ƒZ e Z ee edƒeedƒeed ƒeed!ƒe
d"ƒ d#dd$¡d%d&d'd( dšd*d+œ‡fd,d-„ ƒZee edƒeedƒeed ƒed.d/…d%d0d1d(
d›d2d*d3d4d5d6d7œ‡fd8d9„ ƒZee edƒeeƒedƒeed ƒeed:ƒeed!ƒe
d;ƒ d#dd$¡d%d<d<d(dœd*d3d4d=œ‡fd>d?„ ƒZee edƒeeƒedƒeed ƒeed:ƒed.d/…d%d@dAd( dd.d.dBœd*d3d4d=œ‡fdCdD„ƒZee edƒeeƒedƒeed ƒeed:ƒeed!ƒe
dEƒ d#dd$¡d%dFdGd(džd*d3d4d=œ‡fdHdI„ ƒZee edƒeeƒedƒeed ƒeed:ƒeed!ƒe
dJƒ d#dd$¡d%dKdKd(dŸd*d3d4d=œ‡fdLdM„ ƒZee edƒeeƒedƒeed ƒeed:ƒeed!ƒe
dNƒ d#dd$¡d%dOdOd(d d*d3d4d=œ‡fdPdQ„ ƒZee edƒe
dRƒ d#dd$¡eedSƒedƒeed ƒdTeed:ƒe
dUƒ d#dd$¡ed!ƒe
dVƒ d#dd$¡d%dWdXd(d¡dYd*d3d4dZœ‡fd[d\„ ƒZee edƒe
dRƒ d#dd$¡eedSƒedƒeed ƒd]eed:ƒe
d^ƒ d#dd$¡ed!ƒe
d_ƒ d#dd$¡d%d`dad(d¢dYd*d3d4dZœ‡fdbdc„ ƒZee edƒeedƒeed ƒddeed:ƒded%dfdgd( d£d*d+œ‡fdhdi„ ƒZee edƒe
dRƒ d#dd$¡eedƒeed ƒeed:ƒdjed!ƒe
dkƒ d#dd$¡d%dldmd(d¤dYd*dnœdodp„ƒZ ee edƒeedƒeed ƒdqeed:ƒdred!ƒe
dsƒ d#dd$¡d%dtdud(d¥d*d+œ‡fdvdw„ ƒZ!ee edƒe
dxƒ d#dd$¡eedƒeed ƒeed!ƒe
dyƒ d#dd$¡d%dzdzd( d¦d|d}d*d~œ‡fdd€„ ƒZ"ee dedƒe
d‚ƒ d#dd$¡eedƒeed ƒeed!ƒe
dƒƒ d#dd$¡d%d„d„d(d§d‡d*d*d*dˆœ‡fd‰dŠ„ ƒZ#ee edƒe
d‹ƒ d#dd$¡eedƒeed ƒed.d/…d%dŒdd( d¨dŽddYd*dœ‡fd‘d’„ ƒZ$ee edƒe
d‹ƒ d#dd$¡eedƒeed ƒe
d“ƒ d#dd$¡eed:ƒe
d”ƒ d#dd$¡ed!ƒe
d•ƒ d#dd$¡d%d–d—d(d©dŽddYd*dœ‡fd˜d™„ ƒZ%‡Z&S)ªÚRollingr[rRrSrTrUrVrWrXrYrGrHc
stƒ ¡|jjs$t|jtttfƒrÞt|j    t
t t fƒrÞ|  ¡zt|j    ƒ}Wn:ttfk
r†}ztd|j    ›dƒ|‚W5d}~XYnXt|jtƒr²|j|jjj|jjj|_n|j|_|jdkrÊd|_|jdk    rÜtdƒ‚n.t|j    tƒrìn t|j    ƒr|j    dkr tdƒ‚dS)Nzpassed window z, is not compatible with a datetimelike indexrwz,step is not supported with frequency windowsrr6)rrarQr1r_rJr*r.r-r[rOr rÚ _validate_datetimelike_monotonicrrjr`ZnanosÚfreqÚnr\rRrXrƒr&r)rbr–r¾rrcrdraÖs>
ÿþý ÿý ÿ
 
ÿ zRolling._validaterPrfcCs0|jjr| d¡|jjs,|jjs,| d¡dS)z€
        Validate self._on is monotonic (increasing or decreasing) and has
        no NaT values for frequency windows.
        úvalues must not have NaTzvalues must be monotonicN)rJÚhasnansÚ_raise_monotonic_errorÚis_monotonic_increasingÚis_monotonic_decreasingr˜rcrcrdr•s
z(Rolling._validate_datetimelike_monotonicrO)ÚmsgcCs8|j}|dkr"|jdkrd}nd}t|›d|›ƒ‚dS)Nrr]Úcolumnú )rVrUr`)rbrrVrcrcrdrš
s 
zRolling._raise_monotonic_errorrz³
        See Also
        --------
        pandas.Series.rolling : Calling object with Series data.
        pandas.DataFrame.rolling : Calling object with DataFrame data.
        aì
        Examples
        --------
        >>> df = pd.DataFrame({"A": [1, 2, 3], "B": [4, 5, 6], "C": [7, 8, 9]})
        >>> df
           A  B  C
        0  1  4  7
        1  2  5  8
        2  3  6  9
 
        >>> df.rolling(2).sum()
             A     B     C
        0  NaN   NaN   NaN
        1  3.0   9.0  15.0
        2  5.0  11.0  17.0
 
        >>> df.rolling(2).agg({"A": "sum", "B": "min"})
             A    B
        0  NaN  NaN
        1  3.0  4.0
        2  5.0  5.0
        zSeries/Dataframer=r>cstƒj|f|ž|ŽSr£)rr)rbrèrrœrrcrdrs&zRolling.aggregater@rArBZExamplesa«
        >>> s = pd.Series([2, 3, np.nan, 10])
        >>> s.rolling(2).count()
        0    NaN
        1    2.0
        2    1.0
        3    1.0
        dtype: float64
        >>> s.rolling(3).count()
        0    NaN
        1    NaN
        2    2.0
        3    2.0
        dtype: float64
        >>> s.rolling(4).count()
        0    NaN
        1    NaN
        2    NaN
        3    3.0
        dtype: float64
        Ú
rwrCzcount of non NaN observationsrÓrEFr|rFcs tƒ |¡Sr£)rrÓ©rbr~rrcrdrÓ=s%z Rolling.countNrþzcustom aggregation functionrrërNrürUrVrWcstƒj||||||dS)N)rrXrýrrœ)rr)rbrèrrXrýrrœrrcrdrdsúz Rolling.applyZNotesa]
        >>> s = pd.Series([1, 2, 3, 4, 5])
        >>> s
        0    1
        1    2
        2    3
        3    4
        4    5
        dtype: int64
 
        >>> s.rolling(3).sum()
        0     NaN
        1     NaN
        2     6.0
        3     9.0
        4    12.0
        dtype: float64
 
        >>> s.rolling(3, center=True).sum()
        0     NaN
        1     6.0
        2     9.0
        3    12.0
        4     NaN
        dtype: float64
 
        For DataFrame, each sum is computed column-wise.
 
        >>> df = pd.DataFrame({{"A": s, "B": s ** 2}})
        >>> df
           A   B
        0  1   1
        1  2   4
        2  3   9
        3  4  16
        4  5  25
 
        >>> df.rolling(3).sum()
              A     B
        0   NaN   NaN
        1   NaN   NaN
        2   6.0  14.0
        3   9.0  29.0
        4  12.0  50.0
        rDr^cstƒj|||dS©Nr^)rrD©rbr~rXrýrrcrdrD‚s
Eýz Rolling.sumÚmaximumrd)rXrýcstƒj|||dSr¢)rrd)rbr~rXrýrrœrrcrdrdÍs
ýz Rolling.maxzþ
        Performing a rolling minimum with a window size of 3.
 
        >>> s = pd.Series([4, 3, 5, 2, 6])
        >>> s.rolling(3).min()
        0    NaN
        1    NaN
        2    3.0
        3    2.0
        4    2.0
        dtype: float64
        Zminimumrgcstƒj|||dSr¢)rrgr£rrcrdrgês
$ýz Rolling.mina¢
        The below examples will show rolling mean calculations with window sizes of
        two and three, respectively.
 
        >>> s = pd.Series([1, 2, 3, 4])
        >>> s.rolling(2).mean()
        0    NaN
        1    1.5
        2    2.5
        3    3.5
        dtype: float64
 
        >>> s.rolling(3).mean()
        0    NaN
        1    NaN
        2    2.0
        3    3.0
        dtype: float64
        rKcstƒj|||dSr¢)rrKr£rrcrdrKs
+ýz Rolling.meana 
        Compute the rolling median of a series with a window size of 3.
 
        >>> s = pd.Series([0, 1, 2, 3, 4])
        >>> s.rolling(3).median()
        0    NaN
        1    NaN
        2    1.0
        3    2.0
        4    3.0
        dtype: float64
        rkcstƒj|||dSr¢)rrkr£rrcrdrkEs
$ýzRolling.medianz»
        ddof : int, default 1
            Delta Degrees of Freedom.  The divisor used in calculations
            is ``N - ddof``, where ``N`` represents the number of elements.
        z1.4z/numpy.std : Equivalent method for NumPy array.
        The default ``ddof`` of 1 used in :meth:`Series.std` is different
        than the default ``ddof`` of 0 in :func:`numpy.std`.
 
        A minimum of one period is required for the rolling calculation.
 
        a
 
        >>> s = pd.Series([5, 5, 6, 7, 5, 5, 5])
        >>> s.rolling(3).std()
        0         NaN
        1         NaN
        2    0.577350
        3    1.000000
        4    1.000000
        5    1.154701
        6    0.000000
        dtype: float64
        zstandard deviationrQrsrlcstƒj||||dS©Nrl)rrQ©rbrNr~rXrýrrcrdrQos 4üz Rolling.stdz/numpy.var : Equivalent method for NumPy array.
        The default ``ddof`` of 1 used in :meth:`Series.var` is different
        than the default ``ddof`` of 0 in :func:`numpy.var`.
 
        A minimum of one period is required for the rolling calculation.
 
        a
 
        >>> s = pd.Series([5, 5, 6, 7, 5, 5, 5])
        >>> s.rolling(3).var()
        0         NaN
        1         NaN
        2    0.333333
        3    1.000000
        4    1.000000
        5    1.333333
        6    0.000000
        dtype: float64
        ZvariancerLcstƒj||||dSr¥)rrLr¦rrcrdrLªs 4üz Rolling.varz:scipy.stats.skew : Third moment of a probability density.
zDA minimum of three periods is required for the rolling calculation.
zunbiased skewnessrrcstƒj|dS©NrF)rrrr¡rrcrdrråsz Rolling.skewz:A minimum of one period is required for the calculation.
 
        >>> s = pd.Series([0, 1, 2, 3])
        >>> s.rolling(2, min_periods=1).sem()
        0         NaN
        1    0.707107
        2    0.707107
        3    0.707107
        dtype: float64
        zstandard error of meanrtrMcCs,| d|¡|j|d| |¡| d¡Srsrvrxrcrcrdrt÷s # 
 ÿþz Rolling.semz/scipy.stats.kurtosis : Reference SciPy method.
z<A minimum of four periods is required for the calculation.
 
a]
        The example below will show a rolling calculation with a window size of
        four matching the equivalent function call using `scipy.stats`.
 
        >>> arr = [1, 2, 3, 4, 999]
        >>> import scipy.stats
        >>> print(f"{{scipy.stats.kurtosis(arr[:-1], bias=False):.6f}}")
        -1.200000
        >>> print(f"{{scipy.stats.kurtosis(arr[1:], bias=False):.6f}}")
        3.999946
        >>> s = pd.Series(arr)
        >>> s.rolling(4).kurt()
        0         NaN
        1         NaN
        2         NaN
        3   -1.200000
        4    3.999946
        dtype: float64
        z,Fisher's definition of kurtosis without biasrycstƒj|dSr§)rryr¡rrcrdry    s&z Rolling.kurta‚
        quantile : float
            Quantile to compute. 0 <= quantile <= 1.
        interpolation : {{'linear', 'lower', 'higher', 'midpoint', 'nearest'}}
            This optional parameter specifies the interpolation method to use,
            when the desired quantile lies between two data points `i` and `j`:
 
                * linear: `i + (j - i) * fraction`, where `fraction` is the
                  fractional part of the index surrounded by `i` and `j`.
                * lower: `i`.
                * higher: `j`.
                * nearest: `i` or `j` whichever is nearest.
                * midpoint: (`i` + `j`) / 2.
        ae
        >>> s = pd.Series([1, 2, 3, 4])
        >>> s.rolling(2).quantile(.4, interpolation='lower')
        0    NaN
        1    1.0
        2    2.0
        3    3.0
        dtype: float64
 
        >>> s.rolling(2).quantile(.4, interpolation='midpoint')
        0    NaN
        1    1.5
        2    2.5
        3    3.5
        dtype: float64
        r}rzr{rr|cstƒj|||dS)Nr|)rr})rbr}r~r~rrcrdr}G    s
5ýzRolling.quantilez.. versionadded:: 1.4.0 
 
a
        method : {{'average', 'min', 'max'}}, default 'average'
            How to rank the group of records that have the same value (i.e. ties):
 
            * average: average rank of the group
            * min: lowest rank in the group
            * max: highest rank in the group
 
        ascending : bool, default True
            Whether or not the elements should be ranked in ascending order.
        pct : bool, default False
            Whether or not to display the returned rankings in percentile
            form.
        a(
        >>> s = pd.Series([1, 4, 2, 3, 5, 3])
        >>> s.rolling(3).rank()
        0    NaN
        1    NaN
        2    2.0
        3    2.0
        4    3.0
        5    1.5
        dtype: float64
 
        >>> s.rolling(3).rank(method="max")
        0    NaN
        1    NaN
        2    2.0
        3    2.0
        4    3.0
        5    2.0
        dtype: float64
 
        >>> s.rolling(3).rank(method="min")
        0    NaN
        1    NaN
        2    2.0
        3    2.0
        4    3.0
        5    1.0
        dtype: float64
        rƒrTrr€cstƒj||||dS)Nr€)rrƒ)rbrYrr‚r~rrcrdrƒ‚    s Düz Rolling.ranka
        other : Series or DataFrame, optional
            If not supplied then will default to self and produce pairwise
            output.
        pairwise : bool, default None
            If False then only matching columns between self and other will be
            used and the output will be a DataFrame.
            If True then all pairwise combinations will be calculated and the
            output will be a MultiIndexed DataFrame in the case of DataFrame
            inputs. In the case of missing elements, only complete pairwise
            observations will be used.
        ddof : int, default 1
            Delta Degrees of Freedom.  The divisor used in calculations
            is ``N - ddof``, where ``N`` represents the number of elements.
        zsample covariancer…rârMr„cstƒj||||dS©Nr„)rr…©rbrærçrNr~rrcrdr…Í    s $üz Rolling.covz
        cov : Similar method to calculate covariance.
        numpy.corrcoef : NumPy Pearson's correlation calculation.
        ao
        This function uses Pearson's definition of correlation
        (https://en.wikipedia.org/wiki/Pearson_correlation_coefficient).
 
        When `other` is not specified, the output will be self correlation (e.g.
        all 1's), except for :class:`~pandas.DataFrame` inputs with `pairwise`
        set to `True`.
 
        Function will return ``NaN`` for correlations of equal valued sequences;
        this is the result of a 0/0 division error.
 
        When `pairwise` is set to `False`, only matching columns between `self` and
        `other` will be used.
 
        When `pairwise` is set to `True`, the output will be a MultiIndex DataFrame
        with the original index on the first level, and the `other` DataFrame
        columns on the second level.
 
        In the case of missing elements, only complete pairwise observations
        will be used.
 
        a 
        The below example shows a rolling calculation with a window size of
        four matching the equivalent function call using :meth:`numpy.corrcoef`.
 
        >>> v1 = [3, 3, 3, 5, 8]
        >>> v2 = [3, 4, 4, 4, 8]
        >>> # numpy returns a 2X2 array, the correlation coefficient
        >>> # is the number at entry [0][1]
        >>> print(f"{{np.corrcoef(v1[:-1], v2[:-1])[0][1]:.6f}}")
        0.333333
        >>> print(f"{{np.corrcoef(v1[1:], v2[1:])[0][1]:.6f}}")
        0.916949
        >>> s1 = pd.Series(v1)
        >>> s2 = pd.Series(v2)
        >>> s1.rolling(4).corr(s2)
        0         NaN
        1         NaN
        2         NaN
        3    0.333333
        4    0.916949
        dtype: float64
 
        The below example shows a similar rolling calculation on a
        DataFrame using the pairwise option.
 
        >>> matrix = np.array([[51., 35.], [49., 30.], [47., 32.],        [46., 31.], [50., 36.]])
        >>> print(np.corrcoef(matrix[:-1,0], matrix[:-1,1]).round(7))
        [[1.         0.6263001]
         [0.6263001  1.       ]]
        >>> print(np.corrcoef(matrix[1:,0], matrix[1:,1]).round(7))
        [[1.         0.5553681]
         [0.5553681  1.        ]]
        >>> df = pd.DataFrame(matrix, columns=['X','Y'])
        >>> df
              X     Y
        0  51.0  35.0
        1  49.0  30.0
        2  47.0  32.0
        3  46.0  31.0
        4  50.0  36.0
        >>> df.rolling(4).corr(pairwise=True)
                    X         Y
        0 X       NaN       NaN
          Y       NaN       NaN
        1 X       NaN       NaN
          Y       NaN       NaN
        2 X       NaN       NaN
          Y       NaN       NaN
        3 X  1.000000  0.626300
          Y  0.626300  1.000000
        4 X  1.000000  0.555368
          Y  0.555368  1.000000
        Z correlationrcstƒj||||dSr¨)rrr©rrcrdrø    s {üz Rolling.corr)F)FNNNN)FNN)F)FNN)FNN)FNN)rwFNN)rwFNN)F)rwF)F)rzF)rTFF)NNrwF)NNrwF)'rqrr    rHr rar•ršrr4rrrr9r5r6r:r;ÚreplacerÓr=rr<r8rDrdrgrKrkrQrLrrrtryr}rƒr…rr3rcrcrrdr”ÉsÂ
÷ *
    ÿÿÝ%ÿêÞ$
öù ÿ.Ò/ÃAü 
óþûÿ óä ü ÿìÝ'ü ÿ óä ü ÿúÿùÿ óÕ/ûÿúÿùÿ óÕ/ûóÿúÿ
ö á!ÿìÝ%ÿñÿïÓ2ü ÿñÿâÅ?ûÿð
åûÿðÿûÿêÿ7É8Žvûr”c@s2eZdZdZejejZddœdd„Zdd„ZdS)    ÚRollingGroupbyz3
    Provide a rolling groupby implementation.
    r(rfcCsˆd}|j}t|jtƒrNt|jƒ}|jj ¡}t|tƒs:t‚|     dd¡|j}n |j
dk    rdt }|j
}n
t }|j}t |||jj||d}|S)z“
        Return an indexer class that will compute the window start and end bounds
 
        Returns
        -------
        GroupbyIndexer
        NrÐ)rÐrÑZgroupby_indicesròÚindexer_kwargs)rËr_r[r&rkÚ__dict__rŒÚdictÚAssertionErrorrPr\r)r'r(rr!)rbr¬rÐZrolling_indexerr[ròrcrcrdr°…
s*     
 
ûz"RollingGroupby._get_window_indexercCsj|jjr| d¡|jj ¡D]F}|j |¡}|js|js|j    dkrHdn|j    }t
d|›d|›dƒ‚qdS)zC
        Validate that each group in self._on is monotonic
        r˜Nr]zEach group within z' must be monotonic. Sort the values in z first.) rJr™ršrr!r·rÜr›rœrVr`)rbr(Zgroup_onrVrcrcrdr•¨
s
 ÿÿÿz/RollingGroupby._validate_datetimelike_monotonicN)    rqrr    r
r”rHrr°r•rcrcrcrdr«~
s #r«)sr
__future__rrŒÚdatetimerÚ    functoolsrrlÚtextwraprÚtypingrrrr    r
r r Únumpyr¹Zpandas._libs.tslibsr rZ pandas._libs.window.aggregationsZ_libsr[Z aggregationsrHZpandas._typingrrrrrZpandas.compat._optionalrZ pandas.errorsrZpandas.util._decoratorsrZpandas.core.dtypes.commonrrrrrrrZpandas.core.dtypes.genericrrZpandas.core.dtypes.missingr Zpandas.core._numbar!Zpandas.core.algorithmsr"Zpandas.core.applyr#Zpandas.core.arraysr$Zpandas.core.baser%Zpandas.core.commonÚcoreÚcommonr+Zpandas.core.indexers.objectsr&r'r(r)Zpandas.core.indexes.apir*r+r,r-r.Zpandas.core.reshape.concatr/Zpandas.core.util.numba_r0r1Zpandas.core.window.commonr2r3Zpandas.core.window.docr4r5r6r7r8r9r:r;r<r=Zpandas.core.window.numba_r>r?r@rÃrArBZpandas.core.genericrCrrErFrr4rRr”r«rcrcrcrdÚ<module>sv    $
   $           0   3Ja9