zmc
2023-12-22 9fdbf60165db0400c2e8e6be2dc6e88138ac719a
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
U
¬ý°dšÍã @sìddlmZddlZddlZddlZddlmZmZmZddl    Z    ddl
Z ddl m Z ddlmZmZmZmZddlmZmZmZmZmZmZmZmZmZddlmZddlm Z dd    l!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/dd
l0m1Z1dd l2m3Z3m4Z4m5Z5dd l6m7Z7ed ddZ8e8dk    Z9da:d¯dddœdd„Z;e;e dƒƒGdd„dƒZ<Gdd„dƒZ=ddddœdd „Z>dd!œd"d#„Z?d°dd$d%œd&d'„Z@d(dd)d)d*œd+d,„ZAd±d(dd-d.d)d/d0œd1d2„ZBddd3œd4d5„ZCd²d6d7œd8d9„ZDd:d:d;œd<d=„ZEd(d>d?d@œdAdB„ZFd:d:d;œdCdD„ZGddddEœd(d>dd)ddFœdGdH„ZHddddEœd(d>dd)ddFœdIdJ„ZIe<dKƒeEeGdddddLœd(d>ddMd)dNdOœdPdQ„ƒƒƒZJdRd>dSd(dTdUœdVdW„ZKe<e1ƒe=ƒeEddddEœd(d>dd)dNdFœdXdY„ƒƒƒZLe=ƒddddEœd>ddZœd[d\„ƒZMd]d^d_d-d(d`œdadb„ZNe  Oe jP¡fdcd)d>dMd6dddeœdfdg„ZQe=dhdidddhddjœd>ddMdkœdldm„ƒZRe<dKdnƒe=dhdidddhddjœd>ddMdkœdodp„ƒƒZSe<dKdnƒdddhddjœd(d>ddMd)dNdqœdrds„ƒZTdtdu„ZUeUdvdwdxZVeUdydzdxZWe<d{ƒddddEœd(d>dd)d|dFœd}d~„ƒZXe<d{ƒddddEœd(d>dd)d|dFœdd€„ƒZYe<dKdnƒeGddddEœd(d>dd)dNdFœdd‚„ƒƒZZe<dKdnƒeGddddEœd(d>dd)dNdFœdƒd„„ƒƒZ[e<dKdnƒeGdddddLœd(d>ddMd)dNdOœd…d†„ƒƒZ\d(d>d)dd‡dˆœd‰dŠ„Z]e  Oe jP¡fdcd)d>d6d‹dŒœddŽ„Z^d³dd>d)d]dMddœd‘d’„Z_d]d)dMdd“œd”d•„Z`d–d—„Zae<dKdnƒd˜dd™œd(d(dšd›dNdœœddž„ƒZbdšdŸd œd¡d¢„Zce<dKdnƒddhd£œd(d(d›d›dNd¤œd¥d¦„ƒZdd§d¨„Zed©dª„ZfefejgƒZhefejiƒZjefejkƒZlefejmƒZnefejoƒZpefejqƒZrd«dd«d¬œd­d®„ZsdS)´é)Ú annotationsN)ÚAnyÚCallableÚcast)Ú
get_option)ÚNaTÚNaTTypeÚiNaTÚlib)    Ú    ArrayLikeÚAxisIntÚCorrelationMethodÚDtypeÚDtypeObjÚFÚScalarÚShapeÚnpt)Úimport_optional_dependency)Úfind_stack_level)Úis_any_int_dtypeÚ is_bool_dtypeÚ
is_complexÚis_datetime64_any_dtypeÚis_floatÚis_float_dtypeÚ
is_integerÚis_integer_dtypeÚis_numeric_dtypeÚis_object_dtypeÚ    is_scalarÚis_timedelta64_dtypeÚneeds_i8_conversionÚ pandas_dtype)Ú PeriodDtype)ÚisnaÚna_value_for_dtypeÚnotna)Ú extract_arrayZ
bottleneckÚwarn)ÚerrorsFTÚboolÚNone)ÚvÚreturncCs tr|adS©N)Ú_BOTTLENECK_INSTALLEDÚ_USE_BOTTLENECK)r-©r2úId:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\pandas/core/nanops.pyÚset_use_bottleneckCsr4zcompute.use_bottleneckcsBeZdZdddœ‡fdd„ Zddœdd    „Zd
d
d œd d „Z‡ZS)Údisallowrr,)Údtypesr.cs"tƒ ¡tdd„|Dƒƒ|_dS)Ncss|]}t|ƒjVqdSr/)r#Útype)Ú.0Údtyper2r2r3Ú    <genexpr>Psz$disallow.__init__.<locals>.<genexpr>)ÚsuperÚ__init__Útupler6)Úselfr6©Ú    __class__r2r3r<Ns
zdisallow.__init__r+©r.cCst|dƒot|jj|jƒS)Nr9)ÚhasattrÚ
issubclassr9r7r6)r>Úobjr2r2r3ÚcheckRszdisallow.checkr)Úfr.cs"t ˆ¡‡‡fdd„ƒ}tt|ƒS)Nc
s´t || ¡¡}t‡fdd„|DƒƒrDˆj dd¡}td|›dƒ‚z0tjddˆ||ŽW5QR£WSQRXWn:t    k
r®}zt
|d    ƒrœt|ƒ|‚‚W5d}~XYnXdS)
Nc3s|]}ˆ |¡VqdSr/)rE)r8rD)r>r2r3r:Ysz0disallow.__call__.<locals>._f.<locals>.<genexpr>ÚnanÚzreduction operation 'z' not allowed for this dtypeÚignore©Úinvalidr) Ú    itertoolsÚchainÚvaluesÚanyÚ__name__ÚreplaceÚ    TypeErrorÚnpÚerrstateÚ
ValueErrorr)ÚargsÚkwargsZobj_iterÚf_nameÚe©rFr>r2r3Ú_fVs
ÿ" 
zdisallow.__call__.<locals>._f©Ú    functoolsÚwrapsrr)r>rFr[r2rZr3Ú__call__Uszdisallow.__call__)rPÚ
__module__Ú __qualname__r<rEr_Ú __classcell__r2r2r?r3r5Msr5c@s,eZdZd
ddœdd„Zdddœdd    „ZdS) Úbottleneck_switchNr,rAcKs||_||_dSr/)ÚnamerW)r>rdrWr2r2r3r<nszbottleneck_switch.__init__r)Úaltr.c    spˆjp
ˆj‰zttˆƒ‰Wnttfk
r6d‰YnXt ˆ¡dddœddddœ‡‡‡‡fdd„ƒ}tt    |ƒS)    NT©ÚaxisÚskipnaú
np.ndarrayúAxisInt | Noner+)rNrgrhcsêtˆjƒdkr2ˆj ¡D]\}}||kr|||<q|jdkrT| d¡dkrTt||ƒStrÐ|rÐt|jˆƒrÐ| dd¡dkr¸|     dd¡ˆ|fd|i|—Ž}t
|ƒrΈ|f||dœ|—Ž}qæˆ|f||dœ|—Ž}nˆ|f||dœ|—Ž}|S)NrÚ    min_countÚmaskrgrf) ÚlenrWÚitemsÚsizeÚgetÚ_na_for_min_countr1Ú _bn_ok_dtyper9ÚpopÚ    _has_infs)rNrgrhÚkwdsÚkr-Úresult©reZbn_funcZbn_namer>r2r3rFzs
 
 z%bottleneck_switch.__call__.<locals>.f)
rdrPÚgetattrÚbnÚAttributeErrorÚ    NameErrorr]r^rr)r>rerFr2rxr3r_rs 
ü"'zbottleneck_switch.__call__)N)rPr`rar<r_r2r2r2r3rcmsrcrÚstr)r9rdr.cCst|ƒst|ƒs|dkSdS)N)ÚnansumÚnanprodÚnanmeanF)rr")r9rdr2r2r3rr¥srrrAc    CsVt|tjƒr&|jdkr&t | d¡¡Szt |¡ ¡WSt    t
fk
rPYdSXdS)N)Úf8Zf4ÚKF) Ú
isinstancerSÚndarrayr9r
Zhas_infsZravelÚisinfrOrRÚNotImplementedError)rwr2r2r3rt¹s 
rtz Scalar | None)r9Ú
fill_valuecCsP|dk    r |St|ƒr:|dkr"tjS|dkr0tjStj Sn|dkrHtjStSdS)z9return the correct fill value for the dtype of the valuesNú+inf)Ú _na_ok_dtyperSrGÚinfr
Úi8maxr    )r9r‡Úfill_value_typr2r2r3Ú_get_fill_valueÆs
rriúnpt.NDArray[np.bool_] | None)rNrhrlr.cCs:|dkr6t|jƒst|jƒr dS|s.t|jƒr6t|ƒ}|S)aº
    Compute a mask if and only if necessary.
 
    This function will compute a mask iff it is necessary. Otherwise,
    return the provided mask (potentially None) when a mask does not need to be
    computed.
 
    A mask is never necessary if the values array is of boolean or integer
    dtypes, as these are incapable of storing NaNs. If passing a NaN-capable
    dtype that is interpretable as either boolean or integer data (eg,
    timedelta64), a mask must be provided.
 
    If the skipna parameter is False, a new mask will not be computed.
 
    The mask is computed using isna() by default. Setting invert=True selects
    notna() as the masking function.
 
    Parameters
    ----------
    values : ndarray
        input array to potentially compute mask for
    skipna : bool
        boolean for whether NaNs should be skipped
    mask : Optional[ndarray]
        nan-mask if known
 
    Returns
    -------
    Optional[np.ndarray[bool]]
    N)rr9rr"r%)rNrhrlr2r2r3Ú_maybe_get_maskÜs !rrz
str | NonezHtuple[np.ndarray, npt.NDArray[np.bool_] | None, np.dtype, np.dtype, Any])rNrhr‡rŒrlr.c    Csòt|ƒs t‚t|dd}t|||ƒ}|j}d}t|jƒrLt | d¡¡}d}t    |ƒ}t
|||d}|r®|dk    r®|dk    r®|  ¡r®|s†|rž|  ¡}t  |||¡nt |||¡}|}t|ƒsÂt|ƒrÐt tj¡}nt|ƒrät tj¡}|||||fS)a7
    Utility to get the values view, mask, dtype, dtype_max, and fill_value.
 
    If both mask and fill_value/fill_value_typ are not None and skipna is True,
    the values array will be copied.
 
    For input arrays of boolean or integer dtypes, copies will only occur if a
    precomputed mask, a fill_value/fill_value_typ, and skipna=True are
    provided.
 
    Parameters
    ----------
    values : ndarray
        input array to potentially compute mask for
    skipna : bool
        boolean for whether NaNs should be skipped
    fill_value : Any
        value to fill NaNs with
    fill_value_typ : str
        Set to '+inf' or '-inf' to handle dtype-specific infinities
    mask : Optional[np.ndarray[bool]]
        nan-mask if known
 
    Returns
    -------
    values : ndarray
        Potential copy of input value array
    mask : Optional[ndarray[bool]]
        Mask for values, if deemed necessary to compute
    dtype : np.dtype
        dtype for values
    dtype_max : np.dtype
        platform independent dtype
    fill_value : Any
        fill value used
    T©Z extract_numpyFÚi8)r‡rŒN)r ÚAssertionErrorr(rr9r"rSZasarrayÚviewr‰rrOÚcopyÚputmaskÚwhererrÚint64rÚfloat64)    rNrhr‡rŒrlr9Ú datetimelikeZdtype_okÚ    dtype_maxr2r2r3Ú _get_valuess4.   
ÿ r›)r9r.cCst|ƒr dSt|jtjƒ S)NF)r"rCr7rSÚinteger©r9r2r2r3r‰asr‰znp.dtypercCs|tkr nt|ƒr’|dkr t}t|tjƒs†t|ƒr<tdƒ‚||krJtj}t|ƒrft     dd¡ 
|¡}nt  |¡  |¡}|j
|dd}n
|¡}nzt |ƒr t|tjƒsü||ksºt |¡rÌt d¡ 
|¡}n.t |¡tjkrætdƒ‚nt  |¡j
|dd}n| 
d¡  |¡}|S)    zwrap our results if neededNzExpected non-null fill_valuerÚnsF©r”zoverflow in timedelta operationúm8[ns])rrr    rƒrSr„r%r’rGZ
datetime64Úastyper—r“r!ÚisnanZ timedelta64Úfabsr
r‹rU)rwr9r‡r2r2r3Ú _wrap_resultsgs.  
 
r¤r)Úfuncr.cs6t ˆ¡ddddœdddddœ‡fd    d
„ƒ}tt|ƒS) z˜
    If we have datetime64 or timedelta64 values, ensure we have a correct
    mask before calling the wrapped function, then cast back afterwards.
    NT©rgrhrlrirjr+rŽ)rNrgrhrlcsr|}|jjdk}|r$|dkr$t|ƒ}ˆ|f|||dœ|—Ž}|rnt||jtd}|sn|dk    s`t‚t||||ƒ}|S)N©ÚmÚMr¦)r‡)r9Úkindr%r¤r    r’Ú_mask_datetimelike_result)rNrgrhrlrWÚ orig_valuesr™rw©r¥r2r3Únew_func–s       z&_datetimelike_compat.<locals>.new_funcr\)r¥r®r2r­r3Ú_datetimelike_compats ûr¯rjzScalar | np.ndarray)rNrgr.cCslt|ƒr| d¡}t|jƒ}|jdkr*|S|dkr6|S|jd|…|j|dd…}tj|||jdSdS)a
    Return the missing value for `values`.
 
    Parameters
    ----------
    values : ndarray
    axis : int or None
        axis for the reduction, required if values.ndim > 1.
 
    Returns
    -------
    result : scalar or ndarray
        For 1-D values, returns a scalar of the correct missing type.
        For 2-D values, returns a 1-D array where each element is missing.
    r˜éNr)rr¡r&r9ÚndimÚshaperSÚfull)rNrgr‡Z result_shaper2r2r3rq²s
 
 
 rqcs.t ˆ¡ddœdddœ‡fdd„ƒ}tt|ƒS)z
    NumPy operations on C-contiguous ndarrays with axis=1 can be
    very slow if axis 1 >> axis 0.
    Operate row-by-row and concatenate the results.
    N©rgrirj)rNrgcs¼|dkr¨|jdkr¨|jdr¨|jdd|jdkr¨|jtkr¨|jtkr¨t|ƒ‰ˆ d¡dk    rŠˆ d¡‰‡‡‡‡fdd„t    t
ˆƒƒDƒ}n‡‡fd    d„ˆDƒ}t   |¡Sˆ|fd
|iˆ—ŽS) Nr°éZ C_CONTIGUOUSièrrlcs(g|] }ˆˆ|fdˆ|iˆ—Ž‘qS©rlr2)r8Úi)Úarrsr¥rWrlr2r3Ú
<listcomp>çsz:maybe_operate_rowwise.<locals>.newfunc.<locals>.<listcomp>csg|]}ˆ|fˆŽ‘qSr2r2)r8Úx)r¥rWr2r3r¹ësrg) r±Úflagsr²r9Úobjectr+ÚlistrprsÚrangermrSÚarray)rNrgrWÚresultsr­)r¸rWrlr3ÚnewfuncØs*ÿþýúùø
 
 
ÿ
z&maybe_operate_rowwise.<locals>.newfuncr\)r¥rÁr2r­r3Úmaybe_operate_rowwiseÑsrÂr¦©rNrgrhrlr.cCs^t|jƒr(|jjdkr(tjdttƒdt||d|d\}}}}}t|ƒrT|     t
¡}|  |¡S)a
    Check if any elements along an axis evaluate to True.
 
    Parameters
    ----------
    values : ndarray
    axis : int, optional
    skipna : bool, default True
    mask : ndarray[bool], optional
        nan-mask if known
 
    Returns
    -------
    result : bool
 
    Examples
    --------
    >>> from pandas.core import nanops
    >>> s = pd.Series([1, 2])
    >>> nanops.nanany(s)
    True
 
    >>> from pandas.core import nanops
    >>> s = pd.Series([np.nan])
    >>> nanops.nanany(s)
    False
    r¨zz'any' with datetime64 dtypes is deprecated and will raise in a future version. Use (obj != pd.Timestamp(0)).any() instead.©Ú
stacklevelF©r‡rl) r"r9rªÚwarningsr)Ú FutureWarningrr›rr¡r+rO©rNrgrhrlÚ_r2r2r3Únananyós"ü
rËcCs^t|jƒr(|jjdkr(tjdttƒdt||d|d\}}}}}t|ƒrT|     t
¡}|  |¡S)a
    Check if all elements along an axis evaluate to True.
 
    Parameters
    ----------
    values : ndarray
    axis : int, optional
    skipna : bool, default True
    mask : ndarray[bool], optional
        nan-mask if known
 
    Returns
    -------
    result : bool
 
    Examples
    --------
    >>> from pandas.core import nanops
    >>> s = pd.Series([1, 2, np.nan])
    >>> nanops.nanall(s)
    True
 
    >>> from pandas.core import nanops
    >>> s = pd.Series([1, 0])
    >>> nanops.nanall(s)
    False
    r¨zz'all' with datetime64 dtypes is deprecated and will raise in a future version. Use (obj != pd.Timestamp(0)).all() instead.rÄTrÆ) r"r9rªrÇr)rÈrr›rr¡r+ÚallrÉr2r2r3Únanall*s"ü
rÍZM8)rgrhrkrlÚintÚfloat)rNrgrhrkrlr.c
Csft||d|d\}}}}}|}t|ƒr,|}nt|ƒr@t tj¡}|j||d}    t|    |||j|d}    |    S)aº
    Sum the elements along an axis ignoring NaNs
 
    Parameters
    ----------
    values : ndarray[dtype]
    axis : int, optional
    skipna : bool, default True
    min_count: int, default 0
    mask : ndarray[bool], optional
        nan-mask if known
 
    Returns
    -------
    result : dtype
 
    Examples
    --------
    >>> from pandas.core import nanops
    >>> s = pd.Series([1, 2, np.nan])
    >>> nanops.nansum(s)
    3.0
    rrÆr©rk)    r›rr!rSr9r˜ÚsumÚ_maybe_null_outr²)
rNrgrhrkrlr9ršrÊÚ    dtype_sumÚthe_sumr2r2r3r~as"ÿ r~z+np.ndarray | np.datetime64 | np.timedelta64znpt.NDArray[np.bool_]z5np.ndarray | np.datetime64 | np.timedelta64 | NaTType)rwrgrlr¬r.cCsRt|tjƒr4| d¡ |j¡}|j|d}t||<n| ¡rNt t¡ |j¡S|S)Nr‘r´)    rƒrSr„r¡r“r9rOr    r—)rwrgrlr¬Z    axis_maskr2r2r3r«’s  
r«c     Cst||d|d\}}}}}|}t tj¡}|jdkrBt tj¡}n&t|ƒrXt tj¡}nt|ƒrh|}|}t|j|||d}    t    |j
||dƒ}
|dk    rèt |
ddƒrèt tj |    ƒ}    tjdd    |
|    } W5QRX|    dk} |  ¡rþtj| | <n|    dkrø|
|    ntj} | S)
a
    Compute the mean of the element along an axis ignoring NaNs
 
    Parameters
    ----------
    values : ndarray
    axis : int, optional
    skipna : bool, default True
    mask : ndarray[bool], optional
        nan-mask if known
 
    Returns
    -------
    float
        Unless input is a float array, in which case use the same
        precision as the input array.
 
    Examples
    --------
    >>> from pandas.core import nanops
    >>> s = pd.Series([1, 2, np.nan])
    >>> nanops.nanmean(s)
    1.5
    rrÆr§rNr±FrI©rÌ)r›rSr9r˜rªrrÚ _get_countsr²Ú_ensure_numericrÑryrr„rTrOrG) rNrgrhrlr9ršrÊrÓZ dtype_countÚcountrÔZthe_meanZct_maskr2r2r3r€¥s4"ÿ 
  r€rfc
 
sd
‡fdd„    }t|ˆ|dd\}}}}}t|jƒsrz| d¡}Wn0tk
rp}ztt|ƒƒ|‚W5d}~XYnX|dk    r„tj||<|j    }|j
dkrú|dk    rú|räˆs´t  |||¡}    qøt   ¡ t  dd    t¡t ||¡}    W5QRXnt|j|tjtjƒ}    n|r
|||ƒntj}    t|    |ƒS) aÑ
    Parameters
    ----------
    values : ndarray
    axis : int, optional
    skipna : bool, default True
    mask : ndarray[bool], optional
        nan-mask if known
 
    Returns
    -------
    result : float
        Unless input is a float array, in which case use the same
        precision as the input array.
 
    Examples
    --------
    >>> from pandas.core import nanops
    >>> s = pd.Series([1, np.nan, 2, 2])
    >>> nanops.nanmedian(s)
    2.0
    Nc    s^|dkrt|ƒ}n|}ˆs*| ¡s*tjSt ¡"t ddt¡t ||¡}W5QRX|S)NrIúAll-NaN slice encountered)    r'rÌrSrGrÇÚcatch_warningsÚfilterwarningsÚRuntimeWarningÚ    nanmedian)rºZ_maskÚres©rhr2r3Ú
get_medians
 
ÿznanmedian.<locals>.get_medianr)rlr‡rr°rIrÙ)N)r›rr9r¡rUrRr}rSrGror±Zapply_along_axisrÇrÚrÛrÜrÝÚget_empty_reduction_resultr²Zfloat_r¤)
rNrgrhrlràr9rÊÚerrZnotemptyrÞr2rßr3rÝçs0
 
 
ÿrÝztuple[int, ...]r znp.dtype | type[np.floating])r²rgr9r‡r.cCs<t |¡}t t|ƒ¡}tj|||k|d}| |¡|S)zÑ
    The result from a reduction on an empty ndarray.
 
    Parameters
    ----------
    shape : Tuple[int]
    axis : int
    dtype : np.dtype
    fill_value : Any
 
    Returns
    -------
    np.ndarray
    r)rSr¿ZarangermÚemptyÚfill)r²rgr9r‡ZshpZdimsÚretr2r2r3rá8s
 
 
rárz-tuple[float | np.ndarray, float | np.ndarray])Ú values_shaperlrgÚddofr9r.cCs€t||||d}|| |¡}t|ƒr<||krxtj}tj}n<ttj|ƒ}||k}| ¡rxt ||tj¡t ||tj¡||fS)a:
    Get the count of non-null values along an axis, accounting
    for degrees of freedom.
 
    Parameters
    ----------
    values_shape : Tuple[int, ...]
        shape tuple from values ndarray, used if mask is None
    mask : Optional[ndarray[bool]]
        locations in values that should be considered missing
    axis : Optional[int]
        axis to count along
    ddof : int
        degrees of freedom
    dtype : type, optional
        type to use for count
 
    Returns
    -------
    count : int, np.nan or np.ndarray
    d : int, np.nan or np.ndarray
    r)    rÖr7r rSrGrr„rOr•)rærlrgrçr9rØÚdr2r2r3Ú_get_counts_nanvarSs rér°©rç©rgrhrçrl)rgrhrçc    CsT|jdkr| d¡}|j}t|||d\}}}}}t t|||||d¡}t||ƒS)a´
    Compute the standard deviation along given axis while ignoring NaNs
 
    Parameters
    ----------
    values : ndarray
    axis : int, optional
    skipna : bool, default True
    ddof : int, default 1
        Delta Degrees of Freedom. The divisor used in calculations is N - ddof,
        where N represents the number of elements.
    mask : ndarray[bool], optional
        nan-mask if known
 
    Returns
    -------
    result : float
        Unless input is a float array, in which case use the same
        precision as the input array.
 
    Examples
    --------
    >>> from pandas.core import nanops
    >>> s = pd.Series([1, np.nan, 2, 3])
    >>> nanops.nanstd(s)
    1.0
    zM8[ns]r r¶rë)r9r“r›rSÚsqrtÚnanvarr¤)rNrgrhrçrlZ
orig_dtyperÊrwr2r2r3Únanstd‚s $
 
rîZm8c Cst|dd}|j}t|||ƒ}t|ƒrB| d¡}|dk    rBtj||<t|jƒrft|j    ||||jƒ\}}nt|j    |||ƒ\}}|rœ|dk    rœ| 
¡}t  ||d¡t |j |tjdƒ|}|dk    rÈt ||¡}t ||dƒ}    |dk    rît  |    |d¡|    j |tjd|}
t|ƒr|
j|dd    }
|
S)
aª
    Compute the variance along given axis while ignoring NaNs
 
    Parameters
    ----------
    values : ndarray
    axis : int, optional
    skipna : bool, default True
    ddof : int, default 1
        Delta Degrees of Freedom. The divisor used in calculations is N - ddof,
        where N represents the number of elements.
    mask : ndarray[bool], optional
        nan-mask if known
 
    Returns
    -------
    result : float
        Unless input is a float array, in which case use the same
        precision as the input array.
 
    Examples
    --------
    >>> from pandas.core import nanops
    >>> s = pd.Series([1, np.nan, 2, 3])
    >>> nanops.nanvar(s)
    1.0
    TrrNr)rgr9rµFrŸ)r(r9rrr¡rSrGrrér²r”r•r×rÑr˜Ú expand_dims) rNrgrhrçrlr9rØrèÚavgZsqrrwr2r2r3rí°s.%  
 
 
 
rí)rNrgrhrçrlr.cCsŠt|||||dt|||ƒ}t|jƒs2| d¡}|sL|dk    rL| ¡rLtjSt|j    ||||jƒ\}}t|||||d}t 
|¡t 
|¡S)aÎ
    Compute the standard error in the mean along given axis while ignoring NaNs
 
    Parameters
    ----------
    values : ndarray
    axis : int, optional
    skipna : bool, default True
    ddof : int, default 1
        Delta Degrees of Freedom. The divisor used in calculations is N - ddof,
        where N represents the number of elements.
    mask : ndarray[bool], optional
        nan-mask if known
 
    Returns
    -------
    result : float64
        Unless input is a float array, in which case use the same
        precision as the input array.
 
    Examples
    --------
    >>> from pandas.core import nanops
    >>> s = pd.Series([1, np.nan, 2, 3])
    >>> nanops.nansem(s)
     0.5773502691896258
    rërN) rírrr9r¡rOrSrGrér²rì)rNrgrhrçrlrØrÊÚvarr2r2r3Únansemüs& 
 
ròc    s>tdˆ›dtddddœddddd    d
œ‡‡fd d „ƒƒ}|S) NrG)rdTr¦rirjr+rŽrrÃc
s¢t||ˆ|d\}}}}}|dk    r0|j|dks:|jdkr€z"t|ˆƒ||d}| tj¡WqŽttt    fk
r|tj}YqŽXnt|ˆƒ|ƒ}t
||||jƒ}|S)N©rŒrlrr) r›r²roryrärSrGr{rRrUrÒ)rNrgrhrlr9ršr‡rw©rŒÚmethr2r3Ú    reduction2s    ÿ z_nanminmax.<locals>.reduction)rcr¯)rõrŒrör2rôr3Ú
_nanminmax1sû$r÷Úminrˆ)rŒÚmaxú-infÚOzint | np.ndarraycCs6t|dd|d\}}}}}| |¡}t||||ƒ}|S)aä
    Parameters
    ----------
    values : ndarray
    axis : int, optional
    skipna : bool, default True
    mask : ndarray[bool], optional
        nan-mask if known
 
    Returns
    -------
    result : int or ndarray[int]
        The index/indices  of max value in specified axis or -1 in the NA case
 
    Examples
    --------
    >>> from pandas.core import nanops
    >>> arr = np.array([1, 2, 3, np.nan, 4])
    >>> nanops.nanargmax(arr)
    4
 
    >>> arr = np.array(range(12), dtype=np.float64).reshape(4, 3)
    >>> arr[2:, 2] = np.nan
    >>> arr
    array([[ 0.,  1.,  2.],
           [ 3.,  4.,  5.],
           [ 6.,  7., nan],
           [ 9., 10., nan]])
    >>> nanops.nanargmax(arr, axis=1)
    array([2, 2, 1, 1])
    Trúró)r›ZargmaxÚ_maybe_arg_null_out©rNrgrhrlrÊrwr2r2r3Ú    nanargmaxRs'
rþcCs6t|dd|d\}}}}}| |¡}t||||ƒ}|S)aã
    Parameters
    ----------
    values : ndarray
    axis : int, optional
    skipna : bool, default True
    mask : ndarray[bool], optional
        nan-mask if known
 
    Returns
    -------
    result : int or ndarray[int]
        The index/indices of min value in specified axis or -1 in the NA case
 
    Examples
    --------
    >>> from pandas.core import nanops
    >>> arr = np.array([1, 2, 3, np.nan, 4])
    >>> nanops.nanargmin(arr)
    0
 
    >>> arr = np.array(range(12), dtype=np.float64).reshape(4, 3)
    >>> arr[2:, 0] = np.nan
    >>> arr
    array([[ 0.,  1.,  2.],
           [ 3.,  4.,  5.],
           [nan,  7.,  8.],
           [nan, 10., 11.]])
    >>> nanops.nanargmin(arr, axis=1)
    array([0, 0, 1, 1])
    Trˆró)r›Zargminrürýr2r2r3Ú    nanargmin€s'
rÿc     CsÊt|dd}t|||ƒ}t|jƒs<| d¡}t|j||ƒ}nt|j|||jd}|rt|dk    rt| ¡}t     ||d¡n|sŽ|dk    rŽ| 
¡rŽtj S|j |tj d|}|dk    r¶t ||¡}||}|rØ|dk    rØt     ||d¡|d}||}|j |tj d}    |j |tj d}
t|    ƒ}    t|
ƒ}
tjddd    *||d
d |d|
|    d } W5QRX|j} t| ƒrt| j| d d} t| tjƒr¤t |    dkd| ¡} tj | |dk<n"|    dkr²dn| } |dkrÆtj S| S)aÉ
    Compute the sample skewness.
 
    The statistic computed here is the adjusted Fisher-Pearson standardized
    moment coefficient G1. The algorithm computes this coefficient directly
    from the second and third central moment.
 
    Parameters
    ----------
    values : ndarray
    axis : int, optional
    skipna : bool, default True
    mask : ndarray[bool], optional
        nan-mask if known
 
    Returns
    -------
    result : float64
        Unless input is a float array, in which case use the same
        precision as the input array.
 
    Examples
    --------
    >>> from pandas.core import nanops
    >>> s = pd.Series([1, np.nan, 1, 2])
    >>> nanops.nanskew(s)
    1.7320508075688787
    TrrrNrrµrI©rKÚdivider°gà?gø?FrŸé)r(rrr9r¡rÖr²r”rSr•rOrGrÑr˜rïÚ_zero_out_fperrrTrƒr„r–) rNrgrhrlrØÚmeanÚadjustedÚ    adjusted2Z    adjusted3Úm2Zm3rwr9r2r2r3Únanskew®sF'  
 
   .
 
rc    Cs$t|dd}t|||ƒ}t|jƒs<| d¡}t|j||ƒ}nt|j|||jd}|rt|dk    rt| ¡}t     ||d¡n|sŽ|dk    rŽ| 
¡rŽtj S|j |tj d|}|dk    r¶t ||¡}||}|rØ|dk    rØt     ||d¡|d}|d}|j |tj d}    |j |tj d}
tjddd    Vd
|d d|d|d
} ||d |d |
} |d|d
|    d} W5QRXt| ƒ} t| ƒ} t| tjƒs®|d kr tj S| dkr®dStjddd    | | | }W5QRX|j}t|ƒrò|j|d d}t|tjƒr t | dkd|¡}tj ||d k<|S)aµ
    Compute the sample excess kurtosis
 
    The statistic computed here is the adjusted Fisher-Pearson standardized
    moment coefficient G2, computed directly from the second and fourth
    central moment.
 
    Parameters
    ----------
    values : ndarray
    axis : int, optional
    skipna : bool, default True
    mask : ndarray[bool], optional
        nan-mask if known
 
    Returns
    -------
    result : float64
        Unless input is a float array, in which case use the same
        precision as the input array.
 
    Examples
    --------
    >>> from pandas.core import nanops
    >>> s = pd.Series([1, np.nan, 1, 3, 2])
    >>> nanops.nankurt(s)
    -1.2892561983471076
    TrrrNrrµrIrrr°éFrŸ)r(rrr9r¡rÖr²r”rSr•rOrGrÑr˜rïrTrrƒr„r–)rNrgrhrlrØrrrZ    adjusted4rZm4ZadjÚ    numeratorÚ denominatorrwr9r2r2r3ÚnankurtsR'  
 
    "
 
 
r cCsFt|||ƒ}|r(|dk    r(| ¡}d||<| |¡}t||||j|dS)aÑ
    Parameters
    ----------
    values : ndarray[dtype]
    axis : int, optional
    skipna : bool, default True
    min_count: int, default 0
    mask : ndarray[bool], optional
        nan-mask if known
 
    Returns
    -------
    Dtype
        The product of all elements on a given axis. ( NaNs are treated as 1)
 
    Examples
    --------
    >>> from pandas.core import nanops
    >>> s = pd.Series([1, 2, 3, np.nan])
    >>> nanops.nanprod(s)
    6.0
    Nr°rÐ)rr”ÚprodrÒr²)rNrgrhrkrlrwr2r2r3rks   
ÿrznp.ndarray | int)rwrgrlrhr.cCsn|dkr |S|dks t|ddƒs@|r2| ¡r>dSqj| ¡rjdSn*|rP| |¡}n
| |¡}| ¡rjd||<|S)Nr±Féÿÿÿÿ)ryrÌrO)rwrgrlrhZna_maskr2r2r3rü˜s 
rüzfloat | np.ndarray)rærlrgr9r.cCsz|dkr4|dk    r |j| ¡}n
t |¡}| |¡S|dk    rR|j|| |¡}n||}t|ƒrl| |¡S|j|ddS)a¹
    Get the count of non-null values along an axis
 
    Parameters
    ----------
    values_shape : tuple of int
        shape tuple from values ndarray, used if mask is None
    mask : Optional[ndarray[bool]]
        locations in values that should be considered missing
    axis : Optional[int]
        axis to count along
    dtype : type, optional
        type to use for count
 
    Returns
    -------
    count : scalar or array
    NFrŸ)rorÑrSr r7r²r r¡)rærlrgr9ÚnrØr2r2r3rÖ³s
 
 
rÖznp.ndarray | float | NaTType)rwrgrlr²rkr.c    Cs|dkr|dkr|S|dk    rÚt|tjƒrÚ|dk    rN|j|| |¡|dk}n8|||dk}|d|…||dd…}t ||¡}t |¡rØt|ƒrÐt |¡r®|     d¡}nt
|ƒsÄ|j    ddd}tj ||<nd||<n@|t k    rt |||ƒrt|ddƒ}t
|ƒr| d    ¡}ntj }|S)
zu
    Returns
    -------
    Dtype
        The product of all elements on a given axis. ( NaNs are treated as 1)
    Nrr°Zc16rFrŸr9rG)rƒrSr„r²rÑZ broadcast_torOrZ iscomplexobjr¡rrGrÚcheck_below_min_countryr7)    rwrgrlr²rkZ    null_maskZ below_countZ    new_shapeZ result_dtyper2r2r3rÒÜs.  
 
 
 
 
 rÒ)r²rlrkr.cCs:|dkr6|dkrt |¡}n|j| ¡}||kr6dSdS)aÅ
    Check for the `min_count` keyword. Returns True if below `min_count` (when
    missing value should be returned from the reduction).
 
    Parameters
    ----------
    shape : tuple
        The shape of the values (`values.shape`).
    mask : ndarray[bool] or None
        Boolean numpy array (typically of same shape as `shape`) or None.
    min_count : int
        Keyword passed through from sum/prod call.
 
    Returns
    -------
    bool
    rNTF)rSr rorÑ)r²rlrkZ    non_nullsr2r2r3r s rc
Csht|tjƒrFtjdd&t t |¡dkd|¡W5QR£SQRXnt |¡dkr`|j d¡S|SdS)NrIrJg›+¡†›„=r)rƒrSr„rTr–Úabsr9r7)Úargr2r2r3r+s ,rÚpearson)ÚmethodÚ min_periodsr z
int | None)ÚaÚbrrr.cCspt|ƒt|ƒkrtdƒ‚|dkr$d}t|ƒt|ƒ@}| ¡sL||}||}t|ƒ|kr^tjSt|ƒ}|||ƒS)z
    a, b: ndarrays
    z'Operands to nancorr must have same sizeNr°)rmr’r'rÌrSrGÚ get_corr_func)rrrrÚvalidrFr2r2r3Únancorr4s  rz)Callable[[np.ndarray, np.ndarray], float])rr.cs||dkr$ddlm‰‡fdd„}|S|dkrHddlm‰‡fdd„}|S|d    kr\d
d„}|St|ƒrh|Std |›d ƒ‚dS) NZkendallr©Ú
kendalltaucsˆ||ƒdS©Nrr2©rrrr2r3r¥Wszget_corr_func.<locals>.funcZspearman©Ú    spearmanrcsˆ||ƒdSrr2rrr2r3r¥^srcSst ||¡dS)N©rr°)rSZcorrcoefrr2r2r3r¥dszUnknown method 'z@', expected one of 'kendall', 'spearman', 'pearson', or callable)Z scipy.statsrr ÚcallablerU)rr¥r2)rr r3rQs     
ÿr)rrç)rrrrçr.cCsrt|ƒt|ƒkrtdƒ‚|dkr$d}t|ƒt|ƒ@}| ¡sL||}||}t|ƒ|kr^tjStj|||ddS)Nz&Operands to nancov must have same sizer°rêr!)rmr’r'rÌrSrGZcov)rrrrçrr2r2r3Únancovqs r#c CsHt|tjƒrºt|ƒst|ƒr*| tj¡}nŽt|ƒr¸z| tj¡}Wn^t    t
fk
r z| tj¡}Wn4t
k
rš}zt    d|›dƒ|‚W5d}~XYnXYnXt  t  |¡¡s¸|j }nŠt|ƒsDt|ƒsDt|ƒsDz t|ƒ}Wn^t    t
fk
rBz t|ƒ}Wn6t
k
r<}zt    d|›dƒ|‚W5d}~XYnXYnX|S)NzCould not convert z  to numeric)rƒrSr„rrr¡r˜rZ
complex128rRrUrOÚimagÚrealrrrrÏÚcomplex)rºrâr2r2r3r׊s, *  *r×cs‡fdd„}|S)Nc    sht|ƒ}t|ƒ}||B}tjddˆ||ƒ}W5QRX| ¡rdt|ƒrT| d¡}t ||tj¡|S)NrIrÕrû)r%rSrTrOrr¡r•rG)rºÚyZxmaskZymaskrlrw©Úopr2r3rF«s
zmake_nancomp.<locals>.fr2)r)rFr2r(r3Ú make_nancompªs r*r )rNrhr.c    Cs®tjdtjftjjtj tjftjdtjftjjtjtjfi|\}}|jj    dksVt
‚|ržt |jj tj tjfƒsž| ¡}t|ƒ}|||<||dd}|||<n ||dd}|S)a
    Cumulative function with skipna support.
 
    Parameters
    ----------
    values : np.ndarray or ExtensionArray
    accum_func : {np.cumprod, np.maximum.accumulate, np.cumsum, np.minimum.accumulate}
    skipna : bool
 
    Returns
    -------
    np.ndarray or ExtensionArray
    gð?gr§rr´)rSZcumprodrGÚmaximumÚ
accumulaterŠZcumsumZminimumr9rªr’rCr7rœZbool_r”r%)rNZ
accum_funcrhZmask_aZmask_bÚvalsrlrwr2r2r3Ú na_accum_funcÅs( 
üû 
 r.)T)NN)NNN)N)r°)tÚ
__future__rr]rLÚoperatorÚtypingrrrrÇÚnumpyrSZpandas._configrZ pandas._libsrrr    r
Zpandas._typingr r r rrrrrrZpandas.compat._optionalrZpandas.util._exceptionsrZpandas.core.dtypes.commonrrrrrrrrrrr r!r"r#Zpandas.core.dtypes.dtypesr$Zpandas.core.dtypes.missingr%r&r'Zpandas.core.constructionr(rzr0r1r4r5rcrrrtrrr›r‰r¤r¯rqrÂrËrÍr~r«r€rÝrár9r˜rérîríròr÷ZnanminZnanmaxrþrÿrr rrürÖrÒrrrrr#r×r*ÚgtZnangtÚgeZnangeÚltZnanltÚleZnanleÚeqZnaneqÚneZnanner.r2r2r2r3Ú<module>s  ,  @     8ÿ/ûY)"%û:û7ú".û ?P 
û/ú-úJú4  û-û-ûXûaú +
ü.û0    û û