25
25
import pandas .util ._test_decorators as td
26
26
27
27
28
- def _check_stat_op (self , name , alternative , main_frame , float_frame ,
28
+ def _check_stat_op (name , alternative , main_frame , float_frame ,
29
29
float_string_frame , has_skipna = True ,
30
30
has_numeric_only = False , check_dtype = True ,
31
31
check_dates = False , check_less_precise = False ,
@@ -103,7 +103,7 @@ def wrapper(x):
103
103
tm .assert_series_equal (r1 , expected )
104
104
105
105
106
- def _check_bool_op (self , name , alternative , frame , float_string_frame ,
106
+ def _check_bool_op (name , alternative , frame , float_string_frame ,
107
107
has_skipna = True , has_bool_only = False ):
108
108
109
109
f = getattr (frame , name )
@@ -596,10 +596,10 @@ def test_reduce_mixed_frame(self):
596
596
597
597
def test_count (self , float_frame_with_na , float_frame , float_string_frame ):
598
598
f = lambda s : notna (s ).sum ()
599
- self . _check_stat_op ('count' , f , float_frame_with_na , float_frame ,
600
- float_string_frame , has_skipna = False ,
601
- has_numeric_only = True , check_dtype = False ,
602
- check_dates = True )
599
+ _check_stat_op ('count' , f , float_frame_with_na , float_frame ,
600
+ float_string_frame , has_skipna = False ,
601
+ has_numeric_only = True , check_dtype = False ,
602
+ check_dates = True )
603
603
604
604
# corner case
605
605
frame = DataFrame ()
@@ -628,9 +628,9 @@ def test_count(self, float_frame_with_na, float_frame, float_string_frame):
628
628
def test_nunique (self , float_frame_with_na , float_frame ,
629
629
float_string_frame ):
630
630
f = lambda s : len (algorithms .unique1d (s .dropna ()))
631
- self . _check_stat_op ('nunique' , f , float_frame_with_na ,
632
- float_frame , float_string_frame , has_skipna = False ,
633
- check_dtype = False , check_dates = True )
631
+ _check_stat_op ('nunique' , f , float_frame_with_na ,
632
+ float_frame , float_string_frame , has_skipna = False ,
633
+ check_dtype = False , check_dates = True )
634
634
635
635
df = DataFrame ({'A' : [1 , 1 , 1 ],
636
636
'B' : [1 , 2 , 3 ],
@@ -644,15 +644,15 @@ def test_nunique(self, float_frame_with_na, float_frame,
644
644
645
645
def test_sum (self , float_frame_with_na , mixed_float_frame ,
646
646
float_frame , float_string_frame ):
647
- self . _check_stat_op ('sum' , np .sum , float_frame_with_na , float_frame ,
648
- float_string_frame , has_numeric_only = True ,
649
- skipna_alternative = np .nansum )
647
+ _check_stat_op ('sum' , np .sum , float_frame_with_na , float_frame ,
648
+ float_string_frame , has_numeric_only = True ,
649
+ skipna_alternative = np .nansum )
650
650
651
651
# mixed types (with upcasting happening)
652
- self . _check_stat_op ('sum' , np .sum ,
653
- mixed_float_frame .astype ('float32' ), float_frame ,
654
- float_string_frame , has_numeric_only = True ,
655
- check_dtype = False , check_less_precise = True )
652
+ _check_stat_op ('sum' , np .sum ,
653
+ mixed_float_frame .astype ('float32' ), float_frame ,
654
+ float_string_frame , has_numeric_only = True ,
655
+ check_dtype = False , check_less_precise = True )
656
656
657
657
@pytest .mark .parametrize ('method' , ['sum' , 'mean' , 'prod' , 'var' ,
658
658
'std' , 'skew' , 'min' , 'max' ])
@@ -679,13 +679,13 @@ def test_stat_operators_attempt_obj_array(self, method):
679
679
tm .assert_series_equal (result , expected )
680
680
681
681
def test_mean (self , float_frame_with_na , float_frame , float_string_frame ):
682
- self . _check_stat_op ('mean' , np .mean , float_frame_with_na ,
683
- float_frame , float_string_frame , check_dates = True )
682
+ _check_stat_op ('mean' , np .mean , float_frame_with_na ,
683
+ float_frame , float_string_frame , check_dates = True )
684
684
685
685
def test_product (self , float_frame_with_na , float_frame ,
686
686
float_string_frame ):
687
- self . _check_stat_op ('product' , np .prod , float_frame_with_na ,
688
- float_frame , float_string_frame )
687
+ _check_stat_op ('product' , np .prod , float_frame_with_na ,
688
+ float_frame , float_string_frame )
689
689
690
690
# TODO: Ensure warning isn't emitted in the first place
691
691
@pytest .mark .filterwarnings ("ignore:All-NaN:RuntimeWarning" )
@@ -696,18 +696,18 @@ def wrapper(x):
696
696
return np .nan
697
697
return np .median (x )
698
698
699
- self . _check_stat_op ('median' , wrapper , float_frame_with_na ,
700
- float_frame , float_string_frame , check_dates = True )
699
+ _check_stat_op ('median' , wrapper , float_frame_with_na ,
700
+ float_frame , float_string_frame , check_dates = True )
701
701
702
702
def test_min (self , float_frame_with_na , int_frame ,
703
703
float_frame , float_string_frame ):
704
704
with warnings .catch_warnings (record = True ):
705
705
warnings .simplefilter ("ignore" , RuntimeWarning )
706
- self . _check_stat_op ('min' , np .min , float_frame_with_na ,
707
- float_frame , float_string_frame ,
708
- check_dates = True )
709
- self . _check_stat_op ('min' , np .min , int_frame , float_frame ,
710
- float_string_frame )
706
+ _check_stat_op ('min' , np .min , float_frame_with_na ,
707
+ float_frame , float_string_frame ,
708
+ check_dates = True )
709
+ _check_stat_op ('min' , np .min , int_frame , float_frame ,
710
+ float_string_frame )
711
711
712
712
def test_cummin (self , datetime_frame ):
713
713
datetime_frame .loc [5 :10 , 0 ] = nan
@@ -759,26 +759,26 @@ def test_max(self, float_frame_with_na, int_frame,
759
759
float_frame , float_string_frame ):
760
760
with warnings .catch_warnings (record = True ):
761
761
warnings .simplefilter ("ignore" , RuntimeWarning )
762
- self . _check_stat_op ('max' , np .max , float_frame_with_na ,
763
- float_frame , float_string_frame ,
764
- check_dates = True )
765
- self . _check_stat_op ('max' , np .max , int_frame , float_frame ,
766
- float_string_frame )
762
+ _check_stat_op ('max' , np .max , float_frame_with_na ,
763
+ float_frame , float_string_frame ,
764
+ check_dates = True )
765
+ _check_stat_op ('max' , np .max , int_frame , float_frame ,
766
+ float_string_frame )
767
767
768
768
def test_mad (self , float_frame_with_na , float_frame , float_string_frame ):
769
769
f = lambda x : np .abs (x - x .mean ()).mean ()
770
- self . _check_stat_op ('mad' , f , float_frame_with_na , float_frame ,
771
- float_string_frame )
770
+ _check_stat_op ('mad' , f , float_frame_with_na , float_frame ,
771
+ float_string_frame )
772
772
773
773
def test_var_std (self , float_frame_with_na , datetime_frame , float_frame ,
774
774
float_string_frame ):
775
775
alt = lambda x : np .var (x , ddof = 1 )
776
- self . _check_stat_op ('var' , alt , float_frame_with_na , float_frame ,
777
- float_string_frame )
776
+ _check_stat_op ('var' , alt , float_frame_with_na , float_frame ,
777
+ float_string_frame )
778
778
779
779
alt = lambda x : np .std (x , ddof = 1 )
780
- self . _check_stat_op ('std' , alt , float_frame_with_na , float_frame ,
781
- float_string_frame )
780
+ _check_stat_op ('std' , alt , float_frame_with_na , float_frame ,
781
+ float_string_frame )
782
782
783
783
result = datetime_frame .std (ddof = 4 )
784
784
expected = datetime_frame .apply (lambda x : x .std (ddof = 4 ))
@@ -892,8 +892,8 @@ def test_cumprod(self, datetime_frame):
892
892
def test_sem (self , float_frame_with_na , datetime_frame ,
893
893
float_frame , float_string_frame ):
894
894
alt = lambda x : np .std (x , ddof = 1 ) / np .sqrt (len (x ))
895
- self . _check_stat_op ('sem' , alt , float_frame_with_na ,
896
- float_frame , float_string_frame )
895
+ _check_stat_op ('sem' , alt , float_frame_with_na ,
896
+ float_frame , float_string_frame )
897
897
898
898
result = datetime_frame .sem (ddof = 4 )
899
899
expected = datetime_frame .apply (
@@ -917,8 +917,8 @@ def alt(x):
917
917
return np .nan
918
918
return skew (x , bias = False )
919
919
920
- self . _check_stat_op ('skew' , alt , float_frame_with_na ,
921
- float_frame , float_string_frame )
920
+ _check_stat_op ('skew' , alt , float_frame_with_na ,
921
+ float_frame , float_string_frame )
922
922
923
923
@td .skip_if_no_scipy
924
924
def test_kurt (self , float_frame_with_na , float_frame , float_string_frame ):
@@ -929,8 +929,8 @@ def alt(x):
929
929
return np .nan
930
930
return kurtosis (x , bias = False )
931
931
932
- self . _check_stat_op ('kurt' , alt , float_frame_with_na ,
933
- float_frame , float_string_frame )
932
+ _check_stat_op ('kurt' , alt , float_frame_with_na ,
933
+ float_frame , float_string_frame )
934
934
935
935
index = MultiIndex (levels = [['bar' ], ['one' , 'two' , 'three' ], [0 , 1 ]],
936
936
labels = [[0 , 0 , 0 , 0 , 0 , 0 ],
@@ -1205,9 +1205,9 @@ def wrapper(x):
1205
1205
return np .nan
1206
1206
return np .median (x )
1207
1207
1208
- self . _check_stat_op ('median' , wrapper , int_frame , float_frame ,
1209
- float_string_frame , check_dtype = False ,
1210
- check_dates = True )
1208
+ _check_stat_op ('median' , wrapper , int_frame , float_frame ,
1209
+ float_string_frame , check_dtype = False ,
1210
+ check_dates = True )
1211
1211
1212
1212
# Miscellanea
1213
1213
@@ -1263,12 +1263,12 @@ def test_idxmax(self, float_frame, int_frame):
1263
1263
# Logical reductions
1264
1264
1265
1265
def test_any_all (self , bool_frame_with_na , float_string_frame ):
1266
- self . _check_bool_op ('any' , np .any , bool_frame_with_na ,
1267
- float_string_frame , has_skipna = True ,
1268
- has_bool_only = True )
1269
- self . _check_bool_op ('all' , np .all , bool_frame_with_na ,
1270
- float_string_frame , has_skipna = True ,
1271
- has_bool_only = True )
1266
+ _check_bool_op ('any' , np .any , bool_frame_with_na ,
1267
+ float_string_frame , has_skipna = True ,
1268
+ has_bool_only = True )
1269
+ _check_bool_op ('all' , np .all , bool_frame_with_na ,
1270
+ float_string_frame , has_skipna = True ,
1271
+ has_bool_only = True )
1272
1272
1273
1273
def test_any_all_extra (self ):
1274
1274
df = DataFrame ({
0 commit comments