Skip to content

Commit f258a59

Browse files
committed
collect assert_stat_op_api tests
1 parent e8ffa81 commit f258a59

File tree

1 file changed

+40
-40
lines changed

1 file changed

+40
-40
lines changed

pandas/tests/frame/test_analytics.py

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,31 @@ def test_describe_tz_values(self, tz_naive_fixture):
699699
# ---------------------------------------------------------------------=
700700
# Reductions
701701

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+
702727
def test_reduce_mixed_frame(self):
703728
# GH 6806
704729
df = DataFrame({
@@ -712,13 +737,11 @@ def test_reduce_mixed_frame(self):
712737
np.array([2, 150, 'abcde'], dtype=object))
713738
tm.assert_series_equal(test, df.T.sum(axis=1))
714739

715-
def test_nunique(self, float_frame_with_na, float_frame,
716-
float_string_frame):
740+
def test_nunique(self, float_frame_with_na):
717741
f = lambda s: len(algorithms.unique1d(s.dropna()))
718742
assert_stat_op_calc('nunique', f, float_frame_with_na,
719743
has_skipna=False, check_dtype=False,
720744
check_dates=True)
721-
assert_stat_op_api('nunique', float_frame, float_string_frame)
722745

723746
df = DataFrame({'A': [1, 1, 1],
724747
'B': [1, 2, 3],
@@ -730,10 +753,7 @@ def test_nunique(self, float_frame_with_na, float_frame,
730753
tm.assert_series_equal(df.nunique(axis=1, dropna=False),
731754
Series({0: 1, 1: 3, 2: 2}))
732755

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):
737757
assert_stat_op_calc('sum', np.sum, float_frame_with_na,
738758
skipna_alternative=np.nansum)
739759
# mixed types (with upcasting happening)
@@ -764,61 +784,48 @@ def test_stat_operators_attempt_obj_array(self, method):
764784
if method in ['sum', 'prod']:
765785
tm.assert_series_equal(result, expected)
766786

767-
def test_mean(self, float_frame_with_na, float_frame, float_string_frame):
787+
def test_mean(self, float_frame_with_na):
768788
assert_stat_op_calc('mean', np.mean, float_frame_with_na,
769789
check_dates=True)
770-
assert_stat_op_api('mean', float_frame, float_string_frame)
771790

772-
def test_product(self, float_frame_with_na, float_frame,
773-
float_string_frame):
791+
def test_product(self, float_frame_with_na):
774792
assert_stat_op_calc('product', np.prod, float_frame_with_na)
775-
assert_stat_op_api('product', float_frame, float_string_frame)
776793

777794
# TODO: Ensure warning isn't emitted in the first place
778795
@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):
781797
def wrapper(x):
782798
if isna(x).any():
783799
return np.nan
784800
return np.median(x)
785801

786802
assert_stat_op_calc('median', wrapper, float_frame_with_na,
787803
check_dates=True)
788-
assert_stat_op_api('median', float_frame, float_string_frame)
789804

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):
792806
with warnings.catch_warnings(record=True):
793807
warnings.simplefilter("ignore", RuntimeWarning)
794808
assert_stat_op_calc('min', np.min, float_frame_with_na,
795809
check_dates=True)
796810
assert_stat_op_calc('min', np.min, int_frame)
797-
assert_stat_op_api('min', float_frame, float_string_frame)
798811

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):
801813
with warnings.catch_warnings(record=True):
802814
warnings.simplefilter("ignore", RuntimeWarning)
803815
assert_stat_op_calc('max', np.max, float_frame_with_na,
804816
check_dates=True)
805817
assert_stat_op_calc('max', np.max, int_frame)
806-
assert_stat_op_api('max', float_frame, float_string_frame)
807818

808-
def test_mad(self, float_frame_with_na, float_frame, float_string_frame):
819+
def test_mad(self, float_frame_with_na):
809820
f = lambda x: np.abs(x - x.mean()).mean()
810821
assert_stat_op_calc('mad', f, float_frame_with_na)
811-
assert_stat_op_api('mad', float_frame, float_string_frame)
812822

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):
815824
alt = lambda x: np.var(x, ddof=1)
816825
assert_stat_op_calc('var', alt, float_frame_with_na)
817-
assert_stat_op_api('var', float_frame, float_string_frame)
818826

819827
alt = lambda x: np.std(x, ddof=1)
820828
assert_stat_op_calc('std', alt, float_frame_with_na)
821-
assert_stat_op_api('std', float_frame, float_string_frame)
822829

823830
result = datetime_frame.std(ddof=4)
824831
expected = datetime_frame.apply(lambda x: x.std(ddof=4))
@@ -877,11 +884,9 @@ def test_mixed_ops(self, op):
877884
result = getattr(df, op)()
878885
assert len(result) == 2
879886

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):
882888
alt = lambda x: np.std(x, ddof=1) / np.sqrt(len(x))
883889
assert_stat_op_calc('sem', alt, float_frame_with_na)
884-
assert_stat_op_api('sem', float_frame, float_string_frame)
885890

886891
result = datetime_frame.sem(ddof=4)
887892
expected = datetime_frame.apply(
@@ -897,7 +902,7 @@ def test_sem(self, float_frame_with_na, datetime_frame,
897902
assert not (result < 0).any()
898903

899904
@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):
901906
from scipy.stats import skew
902907

903908
def alt(x):
@@ -906,10 +911,9 @@ def alt(x):
906911
return skew(x, bias=False)
907912

908913
assert_stat_op_calc('skew', alt, float_frame_with_na)
909-
assert_stat_op_api('skew', float_frame, float_string_frame)
910914

911915
@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):
913917
from scipy.stats import kurtosis
914918

915919
def alt(x):
@@ -918,7 +922,6 @@ def alt(x):
918922
return kurtosis(x, bias=False)
919923

920924
assert_stat_op_calc('kurt', alt, float_frame_with_na)
921-
assert_stat_op_api('kurt', float_frame, float_string_frame)
922925

923926
index = MultiIndex(levels=[['bar'], ['one', 'two', 'three'], [0, 1]],
924927
codes=[[0, 0, 0, 0, 0, 0],
@@ -1183,15 +1186,14 @@ def test_stats_mixed_type(self, float_string_frame):
11831186

11841187
# TODO: Ensure warning isn't emitted in the first place
11851188
@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):
11871190
def wrapper(x):
11881191
if isna(x).any():
11891192
return np.nan
11901193
return np.median(x)
11911194

11921195
assert_stat_op_calc('median', wrapper, int_frame, check_dtype=False,
11931196
check_dates=True)
1194-
assert_stat_op_api('median', float_frame, float_string_frame)
11951197

11961198
def test_sum_bools(self):
11971199
df = DataFrame(index=lrange(1), columns=lrange(10))
@@ -1308,12 +1310,10 @@ def test_cummax(self, datetime_frame):
13081310
# ---------------------------------------------------------------------=
13091311
# Miscellanea
13101312

1311-
def test_count(self, float_frame_with_na, float_frame, float_string_frame):
1313+
def test_count(self, float_frame_with_na):
13121314
f = lambda s: notna(s).sum()
13131315
assert_stat_op_calc('count', f, float_frame_with_na, has_skipna=False,
13141316
check_dtype=False, check_dates=True)
1315-
assert_stat_op_api('count', float_frame, float_string_frame,
1316-
has_numeric_only=True)
13171317

13181318
# corner case
13191319
frame = DataFrame()
@@ -1323,7 +1323,7 @@ def test_count(self, float_frame_with_na, float_frame, float_string_frame):
13231323
ct2 = frame.count(0)
13241324
assert isinstance(ct2, Series)
13251325

1326-
# GH 423
1326+
# GH#423
13271327
df = DataFrame(index=lrange(10))
13281328
result = df.count(1)
13291329
expected = Series(0, index=df.index)

0 commit comments

Comments
 (0)