@@ -699,6 +699,31 @@ def test_describe_tz_values(self, tz_naive_fixture):
699
699
# ---------------------------------------------------------------------=
700
700
# Reductions
701
701
702
+ def test_stat_op_api (self , float_frame , float_string_frame ):
703
+ assert_stat_op_api ('count' , float_frame , float_string_frame ,
704
+ has_numeric_only = True )
705
+ assert_stat_op_api ('sum' , float_frame , float_string_frame ,
706
+ has_numeric_only = True )
707
+
708
+ assert_stat_op_api ('nunique' , float_frame , float_string_frame )
709
+ assert_stat_op_api ('mean' , float_frame , float_string_frame )
710
+ assert_stat_op_api ('product' , float_frame , float_string_frame )
711
+ assert_stat_op_api ('median' , float_frame , float_string_frame )
712
+ assert_stat_op_api ('min' , float_frame , float_string_frame )
713
+ assert_stat_op_api ('max' , float_frame , float_string_frame )
714
+ assert_stat_op_api ('mad' , float_frame , float_string_frame )
715
+ assert_stat_op_api ('var' , float_frame , float_string_frame )
716
+ assert_stat_op_api ('std' , float_frame , float_string_frame )
717
+ assert_stat_op_api ('sem' , float_frame , float_string_frame )
718
+ assert_stat_op_api ('median' , float_frame , float_string_frame )
719
+
720
+ try :
721
+ from scipy .stats import skew , kurtosis
722
+ assert_stat_op_api ('skew' , float_frame , float_string_frame )
723
+ assert_stat_op_api ('kurt' , float_frame , float_string_frame )
724
+ except ImportError :
725
+ pass
726
+
702
727
def test_reduce_mixed_frame (self ):
703
728
# GH 6806
704
729
df = DataFrame ({
@@ -712,13 +737,11 @@ def test_reduce_mixed_frame(self):
712
737
np .array ([2 , 150 , 'abcde' ], dtype = object ))
713
738
tm .assert_series_equal (test , df .T .sum (axis = 1 ))
714
739
715
- def test_nunique (self , float_frame_with_na , float_frame ,
716
- float_string_frame ):
740
+ def test_nunique (self , float_frame_with_na ):
717
741
f = lambda s : len (algorithms .unique1d (s .dropna ()))
718
742
assert_stat_op_calc ('nunique' , f , float_frame_with_na ,
719
743
has_skipna = False , check_dtype = False ,
720
744
check_dates = True )
721
- assert_stat_op_api ('nunique' , float_frame , float_string_frame )
722
745
723
746
df = DataFrame ({'A' : [1 , 1 , 1 ],
724
747
'B' : [1 , 2 , 3 ],
@@ -730,10 +753,7 @@ def test_nunique(self, float_frame_with_na, float_frame,
730
753
tm .assert_series_equal (df .nunique (axis = 1 , dropna = False ),
731
754
Series ({0 : 1 , 1 : 3 , 2 : 2 }))
732
755
733
- def test_sum (self , float_frame_with_na , mixed_float_frame ,
734
- float_frame , float_string_frame ):
735
- assert_stat_op_api ('sum' , float_frame , float_string_frame ,
736
- has_numeric_only = True )
756
+ def test_sum (self , float_frame_with_na , mixed_float_frame ):
737
757
assert_stat_op_calc ('sum' , np .sum , float_frame_with_na ,
738
758
skipna_alternative = np .nansum )
739
759
# mixed types (with upcasting happening)
@@ -764,61 +784,48 @@ def test_stat_operators_attempt_obj_array(self, method):
764
784
if method in ['sum' , 'prod' ]:
765
785
tm .assert_series_equal (result , expected )
766
786
767
- def test_mean (self , float_frame_with_na , float_frame , float_string_frame ):
787
+ def test_mean (self , float_frame_with_na ):
768
788
assert_stat_op_calc ('mean' , np .mean , float_frame_with_na ,
769
789
check_dates = True )
770
- assert_stat_op_api ('mean' , float_frame , float_string_frame )
771
790
772
- def test_product (self , float_frame_with_na , float_frame ,
773
- float_string_frame ):
791
+ def test_product (self , float_frame_with_na ):
774
792
assert_stat_op_calc ('product' , np .prod , float_frame_with_na )
775
- assert_stat_op_api ('product' , float_frame , float_string_frame )
776
793
777
794
# TODO: Ensure warning isn't emitted in the first place
778
795
@pytest .mark .filterwarnings ("ignore:All-NaN:RuntimeWarning" )
779
- def test_median (self , float_frame_with_na , float_frame ,
780
- float_string_frame ):
796
+ def test_median (self , float_frame_with_na ):
781
797
def wrapper (x ):
782
798
if isna (x ).any ():
783
799
return np .nan
784
800
return np .median (x )
785
801
786
802
assert_stat_op_calc ('median' , wrapper , float_frame_with_na ,
787
803
check_dates = True )
788
- assert_stat_op_api ('median' , float_frame , float_string_frame )
789
804
790
- def test_min (self , float_frame_with_na , int_frame ,
791
- float_frame , float_string_frame ):
805
+ def test_min (self , float_frame_with_na , int_frame ):
792
806
with warnings .catch_warnings (record = True ):
793
807
warnings .simplefilter ("ignore" , RuntimeWarning )
794
808
assert_stat_op_calc ('min' , np .min , float_frame_with_na ,
795
809
check_dates = True )
796
810
assert_stat_op_calc ('min' , np .min , int_frame )
797
- assert_stat_op_api ('min' , float_frame , float_string_frame )
798
811
799
- def test_max (self , float_frame_with_na , int_frame ,
800
- float_frame , float_string_frame ):
812
+ def test_max (self , float_frame_with_na , int_frame ):
801
813
with warnings .catch_warnings (record = True ):
802
814
warnings .simplefilter ("ignore" , RuntimeWarning )
803
815
assert_stat_op_calc ('max' , np .max , float_frame_with_na ,
804
816
check_dates = True )
805
817
assert_stat_op_calc ('max' , np .max , int_frame )
806
- assert_stat_op_api ('max' , float_frame , float_string_frame )
807
818
808
- def test_mad (self , float_frame_with_na , float_frame , float_string_frame ):
819
+ def test_mad (self , float_frame_with_na ):
809
820
f = lambda x : np .abs (x - x .mean ()).mean ()
810
821
assert_stat_op_calc ('mad' , f , float_frame_with_na )
811
- assert_stat_op_api ('mad' , float_frame , float_string_frame )
812
822
813
- def test_var_std (self , float_frame_with_na , datetime_frame , float_frame ,
814
- float_string_frame ):
823
+ def test_var_std (self , float_frame_with_na , datetime_frame ):
815
824
alt = lambda x : np .var (x , ddof = 1 )
816
825
assert_stat_op_calc ('var' , alt , float_frame_with_na )
817
- assert_stat_op_api ('var' , float_frame , float_string_frame )
818
826
819
827
alt = lambda x : np .std (x , ddof = 1 )
820
828
assert_stat_op_calc ('std' , alt , float_frame_with_na )
821
- assert_stat_op_api ('std' , float_frame , float_string_frame )
822
829
823
830
result = datetime_frame .std (ddof = 4 )
824
831
expected = datetime_frame .apply (lambda x : x .std (ddof = 4 ))
@@ -877,11 +884,9 @@ def test_mixed_ops(self, op):
877
884
result = getattr (df , op )()
878
885
assert len (result ) == 2
879
886
880
- def test_sem (self , float_frame_with_na , datetime_frame ,
881
- float_frame , float_string_frame ):
887
+ def test_sem (self , float_frame_with_na , datetime_frame ):
882
888
alt = lambda x : np .std (x , ddof = 1 ) / np .sqrt (len (x ))
883
889
assert_stat_op_calc ('sem' , alt , float_frame_with_na )
884
- assert_stat_op_api ('sem' , float_frame , float_string_frame )
885
890
886
891
result = datetime_frame .sem (ddof = 4 )
887
892
expected = datetime_frame .apply (
@@ -897,7 +902,7 @@ def test_sem(self, float_frame_with_na, datetime_frame,
897
902
assert not (result < 0 ).any ()
898
903
899
904
@td .skip_if_no_scipy
900
- def test_skew (self , float_frame_with_na , float_frame , float_string_frame ):
905
+ def test_skew (self , float_frame_with_na , float_frame ):
901
906
from scipy .stats import skew
902
907
903
908
def alt (x ):
@@ -906,10 +911,9 @@ def alt(x):
906
911
return skew (x , bias = False )
907
912
908
913
assert_stat_op_calc ('skew' , alt , float_frame_with_na )
909
- assert_stat_op_api ('skew' , float_frame , float_string_frame )
910
914
911
915
@td .skip_if_no_scipy
912
- def test_kurt (self , float_frame_with_na , float_frame , float_string_frame ):
916
+ def test_kurt (self , float_frame_with_na , float_frame ):
913
917
from scipy .stats import kurtosis
914
918
915
919
def alt (x ):
@@ -918,7 +922,6 @@ def alt(x):
918
922
return kurtosis (x , bias = False )
919
923
920
924
assert_stat_op_calc ('kurt' , alt , float_frame_with_na )
921
- assert_stat_op_api ('kurt' , float_frame , float_string_frame )
922
925
923
926
index = MultiIndex (levels = [['bar' ], ['one' , 'two' , 'three' ], [0 , 1 ]],
924
927
codes = [[0 , 0 , 0 , 0 , 0 , 0 ],
@@ -1183,15 +1186,14 @@ def test_stats_mixed_type(self, float_string_frame):
1183
1186
1184
1187
# TODO: Ensure warning isn't emitted in the first place
1185
1188
@pytest .mark .filterwarnings ("ignore:All-NaN:RuntimeWarning" )
1186
- def test_median_corner (self , int_frame , float_frame , float_string_frame ):
1189
+ def test_median_corner (self , int_frame , float_frame ):
1187
1190
def wrapper (x ):
1188
1191
if isna (x ).any ():
1189
1192
return np .nan
1190
1193
return np .median (x )
1191
1194
1192
1195
assert_stat_op_calc ('median' , wrapper , int_frame , check_dtype = False ,
1193
1196
check_dates = True )
1194
- assert_stat_op_api ('median' , float_frame , float_string_frame )
1195
1197
1196
1198
def test_sum_bools (self ):
1197
1199
df = DataFrame (index = lrange (1 ), columns = lrange (10 ))
@@ -1308,12 +1310,10 @@ def test_cummax(self, datetime_frame):
1308
1310
# ---------------------------------------------------------------------=
1309
1311
# Miscellanea
1310
1312
1311
- def test_count (self , float_frame_with_na , float_frame , float_string_frame ):
1313
+ def test_count (self , float_frame_with_na ):
1312
1314
f = lambda s : notna (s ).sum ()
1313
1315
assert_stat_op_calc ('count' , f , float_frame_with_na , has_skipna = False ,
1314
1316
check_dtype = False , check_dates = True )
1315
- assert_stat_op_api ('count' , float_frame , float_string_frame ,
1316
- has_numeric_only = True )
1317
1317
1318
1318
# corner case
1319
1319
frame = DataFrame ()
@@ -1323,7 +1323,7 @@ def test_count(self, float_frame_with_na, float_frame, float_string_frame):
1323
1323
ct2 = frame .count (0 )
1324
1324
assert isinstance (ct2 , Series )
1325
1325
1326
- # GH 423
1326
+ # GH# 423
1327
1327
df = DataFrame (index = lrange (10 ))
1328
1328
result = df .count (1 )
1329
1329
expected = Series (0 , index = df .index )
0 commit comments