From 6b5b392147256fc19e1a1befbb012389a22bbd7d Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Fri, 18 Jan 2019 09:18:57 +0000 Subject: [PATCH 1/2] TST: patch changes to pandas.util.testing --- pandas/tests/indexing/multiindex/conftest.py | 7 ++++--- pandas/tests/plotting/test_datetimelike.py | 9 ++++----- pandas/tests/reshape/merge/test_join.py | 8 ++++---- pandas/tests/series/test_alter_axes.py | 4 ++-- pandas/tests/test_multilevel.py | 2 ++ 5 files changed, 16 insertions(+), 14 deletions(-) diff --git a/pandas/tests/indexing/multiindex/conftest.py b/pandas/tests/indexing/multiindex/conftest.py index 046fc19c0d9c8..d5acffee2511d 100644 --- a/pandas/tests/indexing/multiindex/conftest.py +++ b/pandas/tests/indexing/multiindex/conftest.py @@ -18,11 +18,12 @@ def multiindex_dataframe_random_data(): @pytest.fixture -def multiindex_year_month_day_dataframe_random_data(): +def multiindex_year_month_day_dataframe_random_data(monkeypatch): """DataFrame with 3 level MultiIndex (year, month, day) covering first 100 business days from 2000-01-01 with random data""" - tm.N = 100 - tdf = tm.makeTimeDataFrame() + with monkeypatch.context() as m: + m.setattr("pandas.util.testing.N", 100) + tdf = tm.makeTimeDataFrame() ymd = tdf.groupby([lambda x: x.year, lambda x: x.month, lambda x: x.day]).sum() # use Int64Index, to make sure things work diff --git a/pandas/tests/plotting/test_datetimelike.py b/pandas/tests/plotting/test_datetimelike.py index c78ab41d2fae4..a95d5cc8739b3 100644 --- a/pandas/tests/plotting/test_datetimelike.py +++ b/pandas/tests/plotting/test_datetimelike.py @@ -312,11 +312,10 @@ def test_business_freq(self): assert PeriodIndex(data=idx).freqstr == 'B' @pytest.mark.slow - def test_business_freq_convert(self): - n = tm.N - tm.N = 300 - bts = tm.makeTimeSeries().asfreq('BM') - tm.N = n + def test_business_freq_convert(self, monkeypatch): + with monkeypatch.context() as m: + m.setattr("pandas.util.testing.N", 300) + bts = tm.makeTimeSeries().asfreq('BM') ts = bts.to_period('M') _, ax = self.plt.subplots() bts.plot(ax=ax) diff --git a/pandas/tests/reshape/merge/test_join.py b/pandas/tests/reshape/merge/test_join.py index 8ee1e49f01ac1..4cd8ba360768a 100644 --- a/pandas/tests/reshape/merge/test_join.py +++ b/pandas/tests/reshape/merge/test_join.py @@ -697,11 +697,11 @@ def test_panel_join_overlap(self): expected = no_overlap.join(p1_suf.join(p2_suf)) tm.assert_panel_equal(joined, expected) - def test_panel_join_many(self): + def test_panel_join_many(self, monkeypatch): with catch_warnings(record=True): - tm.K = 10 - panel = tm.makePanel() - tm.K = 4 + with monkeypatch.context() as m: + m.setattr("pandas.util.testing.K", 10) + panel = tm.makePanel() panels = [panel.iloc[:2], panel.iloc[2:6], panel.iloc[6:]] diff --git a/pandas/tests/series/test_alter_axes.py b/pandas/tests/series/test_alter_axes.py index cd4c0a7924d39..04c54bcf8c22c 100644 --- a/pandas/tests/series/test_alter_axes.py +++ b/pandas/tests/series/test_alter_axes.py @@ -22,8 +22,8 @@ def test_setindex(self, string_series): string_series.index = None # wrong length - msg = (r"Length mismatch: Expected axis has (30|100) elements, new" - r" values have (29|99) elements") + msg = ("Length mismatch: Expected axis has 30 elements, new" + " values have 29 elements") with pytest.raises(ValueError, match=msg): string_series.index = np.arange(len(string_series) - 1) diff --git a/pandas/tests/test_multilevel.py b/pandas/tests/test_multilevel.py index b5023c376dedd..7423e1c60303d 100644 --- a/pandas/tests/test_multilevel.py +++ b/pandas/tests/test_multilevel.py @@ -47,8 +47,10 @@ def setup_method(self, method): s[3] = np.NaN self.series = s + n = tm.N tm.N = 100 self.tdf = tm.makeTimeDataFrame() + tm.N = n self.ymd = self.tdf.groupby([lambda x: x.year, lambda x: x.month, lambda x: x.day]).sum() From be9ff97d4528e2af3604b3d4fd9730fa8346d419 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Fri, 18 Jan 2019 12:44:36 +0000 Subject: [PATCH 2/2] remove monkeypatch --- pandas/tests/indexing/multiindex/conftest.py | 6 ++---- pandas/tests/plotting/test_datetimelike.py | 6 ++---- pandas/tests/reshape/merge/test_join.py | 8 ++++---- pandas/tests/test_multilevel.py | 5 +---- 4 files changed, 9 insertions(+), 16 deletions(-) diff --git a/pandas/tests/indexing/multiindex/conftest.py b/pandas/tests/indexing/multiindex/conftest.py index d5acffee2511d..545e092d9ce65 100644 --- a/pandas/tests/indexing/multiindex/conftest.py +++ b/pandas/tests/indexing/multiindex/conftest.py @@ -18,12 +18,10 @@ def multiindex_dataframe_random_data(): @pytest.fixture -def multiindex_year_month_day_dataframe_random_data(monkeypatch): +def multiindex_year_month_day_dataframe_random_data(): """DataFrame with 3 level MultiIndex (year, month, day) covering first 100 business days from 2000-01-01 with random data""" - with monkeypatch.context() as m: - m.setattr("pandas.util.testing.N", 100) - tdf = tm.makeTimeDataFrame() + tdf = tm.makeTimeDataFrame(100) ymd = tdf.groupby([lambda x: x.year, lambda x: x.month, lambda x: x.day]).sum() # use Int64Index, to make sure things work diff --git a/pandas/tests/plotting/test_datetimelike.py b/pandas/tests/plotting/test_datetimelike.py index a95d5cc8739b3..ad79cc97f8b77 100644 --- a/pandas/tests/plotting/test_datetimelike.py +++ b/pandas/tests/plotting/test_datetimelike.py @@ -312,10 +312,8 @@ def test_business_freq(self): assert PeriodIndex(data=idx).freqstr == 'B' @pytest.mark.slow - def test_business_freq_convert(self, monkeypatch): - with monkeypatch.context() as m: - m.setattr("pandas.util.testing.N", 300) - bts = tm.makeTimeSeries().asfreq('BM') + def test_business_freq_convert(self): + bts = tm.makeTimeSeries(300).asfreq('BM') ts = bts.to_period('M') _, ax = self.plt.subplots() bts.plot(ax=ax) diff --git a/pandas/tests/reshape/merge/test_join.py b/pandas/tests/reshape/merge/test_join.py index 4cd8ba360768a..8ee1e49f01ac1 100644 --- a/pandas/tests/reshape/merge/test_join.py +++ b/pandas/tests/reshape/merge/test_join.py @@ -697,11 +697,11 @@ def test_panel_join_overlap(self): expected = no_overlap.join(p1_suf.join(p2_suf)) tm.assert_panel_equal(joined, expected) - def test_panel_join_many(self, monkeypatch): + def test_panel_join_many(self): with catch_warnings(record=True): - with monkeypatch.context() as m: - m.setattr("pandas.util.testing.K", 10) - panel = tm.makePanel() + tm.K = 10 + panel = tm.makePanel() + tm.K = 4 panels = [panel.iloc[:2], panel.iloc[2:6], panel.iloc[6:]] diff --git a/pandas/tests/test_multilevel.py b/pandas/tests/test_multilevel.py index 7423e1c60303d..a7bbbbb5033ac 100644 --- a/pandas/tests/test_multilevel.py +++ b/pandas/tests/test_multilevel.py @@ -47,10 +47,7 @@ def setup_method(self, method): s[3] = np.NaN self.series = s - n = tm.N - tm.N = 100 - self.tdf = tm.makeTimeDataFrame() - tm.N = n + self.tdf = tm.makeTimeDataFrame(100) self.ymd = self.tdf.groupby([lambda x: x.year, lambda x: x.month, lambda x: x.day]).sum()