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..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,9 +43,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() self.tsframe = _tsframe.copy() self.mixed_frame = _mixed_frame.copy() @@ -54,10 +50,6 @@ def setup(self): yield - del self.empty_frame - - del self.frame - del self.frame2 del self.intframe del self.tsframe del self.mixed_frame @@ -126,19 +118,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) @@ -226,12 +218,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: @@ -738,11 +730,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, - self.frame2, + float_frame, self.intframe, self.tsframe, self.mixed_frame, 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)