From 14be57d3c284b47b22a93ea4e6d285e2d0520e3d Mon Sep 17 00:00:00 2001 From: Will Ayd Date: Mon, 30 Mar 2020 10:49:54 -0700 Subject: [PATCH 1/3] empty_series fixture --- pandas/conftest.py | 5 +++++ pandas/tests/io/json/test_pandas.py | 9 +++------ pandas/tests/resample/conftest.py | 2 +- pandas/tests/resample/test_base.py | 22 ++++++++++------------ 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/pandas/conftest.py b/pandas/conftest.py index ad21d46e601e8..2ee64403c7cf4 100644 --- a/pandas/conftest.py +++ b/pandas/conftest.py @@ -521,6 +521,11 @@ def index_or_series_obj(request): # ---------------------------------------------------------------- # DataFrames # ---------------------------------------------------------------- +@pytest.fixture +def empty_frame(): + return DataFrame() + + @pytest.fixture def float_frame(): """ diff --git a/pandas/tests/io/json/test_pandas.py b/pandas/tests/io/json/test_pandas.py index e13b2b34d611b..2b6ddd9a139ca 100644 --- a/pandas/tests/io/json/test_pandas.py +++ b/pandas/tests/io/json/test_pandas.py @@ -44,7 +44,6 @@ def assert_json_roundtrip_equal(result, expected, orient): class TestPandasContainer: @pytest.fixture(autouse=True) def setup(self): - self.empty_frame = DataFrame() self.frame = _frame.copy() self.frame2 = _frame2.copy() self.intframe = _intframe.copy() @@ -54,8 +53,6 @@ def setup(self): yield - del self.empty_frame - del self.frame del self.frame2 del self.intframe @@ -226,12 +223,12 @@ def test_roundtrip_categorical(self, orient, convert_axes, numpy): @pytest.mark.parametrize("convert_axes", [True, False]) @pytest.mark.parametrize("numpy", [True, False]) - def test_roundtrip_empty(self, orient, convert_axes, numpy): - data = self.empty_frame.to_json(orient=orient) + def test_roundtrip_empty(self, orient, convert_axes, numpy, empty_frame): + data = empty_frame.to_json(orient=orient) result = pd.read_json( data, orient=orient, convert_axes=convert_axes, numpy=numpy ) - expected = self.empty_frame.copy() + expected = empty_frame.copy() # TODO: both conditions below are probably bugs if convert_axes: diff --git a/pandas/tests/resample/conftest.py b/pandas/tests/resample/conftest.py index fb2111a60a261..fa53e49269f8b 100644 --- a/pandas/tests/resample/conftest.py +++ b/pandas/tests/resample/conftest.py @@ -153,7 +153,7 @@ def frame(index, _series_name, _static_values): @pytest.fixture -def empty_frame(series): +def empty_frame_dti(series): """ Fixture for parametrization of empty DataFrame with date_range, period_range and timedelta_range indexes diff --git a/pandas/tests/resample/test_base.py b/pandas/tests/resample/test_base.py index 3384c2a94487b..6384c5f19c898 100644 --- a/pandas/tests/resample/test_base.py +++ b/pandas/tests/resample/test_base.py @@ -127,9 +127,9 @@ def test_resample_count_empty_series(freq, empty_series_dti, resample_method): @all_ts @pytest.mark.parametrize("freq", ["M", "D", "H"]) -def test_resample_empty_dataframe(empty_frame, freq, resample_method): +def test_resample_empty_dataframe(empty_frame_dti, freq, resample_method): # GH13212 - df = empty_frame + df = empty_frame_dti # count retains dimensions too result = getattr(df.resample(freq), resample_method)() if resample_method != "size": @@ -149,15 +149,14 @@ def test_resample_empty_dataframe(empty_frame, freq, resample_method): @all_ts @pytest.mark.parametrize("freq", ["M", "D", "H"]) -def test_resample_count_empty_dataframe(freq, empty_frame): +def test_resample_count_empty_dataframe(freq, empty_frame_dti): # GH28427 - empty_frame = empty_frame.copy() - empty_frame["a"] = [] + empty_frame_dti["a"] = [] - result = empty_frame.resample(freq).count() + result = empty_frame_dti.resample(freq).count() - index = _asfreq_compat(empty_frame.index, freq) + index = _asfreq_compat(empty_frame_dti.index, freq) expected = pd.DataFrame({"a": []}, dtype="int64", index=index) @@ -166,15 +165,14 @@ def test_resample_count_empty_dataframe(freq, empty_frame): @all_ts @pytest.mark.parametrize("freq", ["M", "D", "H"]) -def test_resample_size_empty_dataframe(freq, empty_frame): +def test_resample_size_empty_dataframe(freq, empty_frame_dti): # GH28427 - empty_frame = empty_frame.copy() - empty_frame["a"] = [] + empty_frame_dti["a"] = [] - result = empty_frame.resample(freq).size() + result = empty_frame_dti.resample(freq).size() - index = _asfreq_compat(empty_frame.index, freq) + index = _asfreq_compat(empty_frame_dti.index, freq) expected = pd.Series([], dtype="int64", index=index) From 388cb72a47a9f3d9dafd11993ec2841844109b29 Mon Sep 17 00:00:00 2001 From: Will Ayd Date: Mon, 30 Mar 2020 10:52:43 -0700 Subject: [PATCH 2/3] float_frame usage --- pandas/tests/io/json/test_pandas.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/pandas/tests/io/json/test_pandas.py b/pandas/tests/io/json/test_pandas.py index 2b6ddd9a139ca..fc010763937a5 100644 --- a/pandas/tests/io/json/test_pandas.py +++ b/pandas/tests/io/json/test_pandas.py @@ -44,7 +44,6 @@ def assert_json_roundtrip_equal(result, expected, orient): class TestPandasContainer: @pytest.fixture(autouse=True) def setup(self): - self.frame = _frame.copy() self.frame2 = _frame2.copy() self.intframe = _intframe.copy() self.tsframe = _tsframe.copy() @@ -53,7 +52,6 @@ def setup(self): yield - del self.frame del self.frame2 del self.intframe del self.tsframe @@ -123,19 +121,19 @@ def test_frame_non_unique_columns_raises(self, orient): with pytest.raises(ValueError, match=msg): df.to_json(orient=orient) - def test_frame_default_orient(self): - assert self.frame.to_json() == self.frame.to_json(orient="columns") + def test_frame_default_orient(self, float_frame): + assert float_frame.to_json() == float_frame.to_json(orient="columns") @pytest.mark.parametrize("dtype", [False, float]) @pytest.mark.parametrize("convert_axes", [True, False]) @pytest.mark.parametrize("numpy", [True, False]) - def test_roundtrip_simple(self, orient, convert_axes, numpy, dtype): - data = self.frame.to_json(orient=orient) + def test_roundtrip_simple(self, orient, convert_axes, numpy, dtype, float_frame): + data = float_frame.to_json(orient=orient) result = pd.read_json( data, orient=orient, convert_axes=convert_axes, numpy=numpy, dtype=dtype ) - expected = self.frame.copy() + expected = float_frame assert_json_roundtrip_equal(result, expected, orient) @@ -735,10 +733,10 @@ def test_reconstruction_index(self): result = read_json(df.to_json()) tm.assert_frame_equal(result, df) - def test_path(self): + def test_path(self, float_frame): with tm.ensure_clean("test.json") as path: for df in [ - self.frame, + float_frame, self.frame2, self.intframe, self.tsframe, From 5d4af6e3a20573c884be9d22ddbeae0b79eaaeb8 Mon Sep 17 00:00:00 2001 From: Will Ayd Date: Mon, 30 Mar 2020 10:53:52 -0700 Subject: [PATCH 3/3] removed frame2 --- pandas/tests/io/json/test_pandas.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/pandas/tests/io/json/test_pandas.py b/pandas/tests/io/json/test_pandas.py index fc010763937a5..6a7a81e88d318 100644 --- a/pandas/tests/io/json/test_pandas.py +++ b/pandas/tests/io/json/test_pandas.py @@ -19,7 +19,6 @@ _tsd = tm.getTimeSeriesData() _frame = DataFrame(_seriesd) -_frame2 = DataFrame(_seriesd, columns=["D", "C", "B", "A"]) _intframe = DataFrame({k: v.astype(np.int64) for k, v in _seriesd.items()}) _tsframe = DataFrame(_tsd) @@ -44,7 +43,6 @@ def assert_json_roundtrip_equal(result, expected, orient): class TestPandasContainer: @pytest.fixture(autouse=True) def setup(self): - self.frame2 = _frame2.copy() self.intframe = _intframe.copy() self.tsframe = _tsframe.copy() self.mixed_frame = _mixed_frame.copy() @@ -52,7 +50,6 @@ def setup(self): yield - del self.frame2 del self.intframe del self.tsframe del self.mixed_frame @@ -737,7 +734,6 @@ def test_path(self, float_frame): with tm.ensure_clean("test.json") as path: for df in [ float_frame, - self.frame2, self.intframe, self.tsframe, self.mixed_frame,