From 32315d66c210126d1163cb3882b8532a0e0f3ad4 Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Sun, 23 Jun 2019 12:26:49 -0700 Subject: [PATCH 1/2] Fix flaky test --- pandas/tests/resample/test_resample_api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/resample/test_resample_api.py b/pandas/tests/resample/test_resample_api.py index 7157ecccace00..2de763bcaaf7e 100644 --- a/pandas/tests/resample/test_resample_api.py +++ b/pandas/tests/resample/test_resample_api.py @@ -145,7 +145,7 @@ def test_api_compat_before_use(): def tests_skip_nuisance(): - df = test_frame + df = test_frame.copy() df['D'] = 'foo' r = df.resample('H') result = r[['A', 'B']].sum() From ec2bf38f5e54846a86897e2d0fab2e98eecb30a6 Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Sun, 23 Jun 2019 13:32:51 -0700 Subject: [PATCH 2/2] make fixture --- pandas/tests/resample/test_resample_api.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/pandas/tests/resample/test_resample_api.py b/pandas/tests/resample/test_resample_api.py index 2de763bcaaf7e..ca2fb1acb6afa 100644 --- a/pandas/tests/resample/test_resample_api.py +++ b/pandas/tests/resample/test_resample_api.py @@ -14,10 +14,15 @@ end=datetime(2005, 1, 10), freq='Min') test_series = Series(np.random.rand(len(dti)), dti) -test_frame = DataFrame( +_test_frame = DataFrame( {'A': test_series, 'B': test_series, 'C': np.arange(len(dti))}) +@pytest.fixture +def test_frame(): + return _test_frame.copy() + + def test_str(): r = test_series.resample('H') @@ -76,7 +81,7 @@ def test_groupby_resample_on_api(): assert_frame_equal(result, expected) -def test_pipe(): +def test_pipe(test_frame): # GH17905 # series @@ -92,7 +97,7 @@ def test_pipe(): tm.assert_frame_equal(result, expected) -def test_getitem(): +def test_getitem(test_frame): r = test_frame.resample('H') tm.assert_index_equal(r._selected_obj.columns, test_frame.columns) @@ -111,7 +116,7 @@ def test_getitem(): @pytest.mark.parametrize('key', [['D'], ['A', 'D']]) -def test_select_bad_cols(key): +def test_select_bad_cols(key, test_frame): g = test_frame.resample('H') # 'A' should not be referenced as a bad column... # will have to rethink regex if you change message! @@ -120,7 +125,7 @@ def test_select_bad_cols(key): g[key] -def test_attribute_access(): +def test_attribute_access(test_frame): r = test_frame.resample('H') tm.assert_series_equal(r.A.sum(), r['A'].sum()) @@ -143,9 +148,9 @@ def test_api_compat_before_use(): getattr(rs, attr) -def tests_skip_nuisance(): +def tests_skip_nuisance(test_frame): - df = test_frame.copy() + df = test_frame df['D'] = 'foo' r = df.resample('H') result = r[['A', 'B']].sum()