Skip to content

Commit 32d8754

Browse files
authored
More Json parametrize (#33148)
1 parent 287872f commit 32d8754

File tree

4 files changed

+26
-32
lines changed

4 files changed

+26
-32
lines changed

pandas/conftest.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,11 @@ def index_or_series_obj(request):
521521
# ----------------------------------------------------------------
522522
# DataFrames
523523
# ----------------------------------------------------------------
524+
@pytest.fixture
525+
def empty_frame():
526+
return DataFrame()
527+
528+
524529
@pytest.fixture
525530
def float_frame():
526531
"""

pandas/tests/io/json/test_pandas.py

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
_tsd = tm.getTimeSeriesData()
2020

2121
_frame = DataFrame(_seriesd)
22-
_frame2 = DataFrame(_seriesd, columns=["D", "C", "B", "A"])
2322
_intframe = DataFrame({k: v.astype(np.int64) for k, v in _seriesd.items()})
2423

2524
_tsframe = DataFrame(_tsd)
@@ -44,20 +43,13 @@ def assert_json_roundtrip_equal(result, expected, orient):
4443
class TestPandasContainer:
4544
@pytest.fixture(autouse=True)
4645
def setup(self):
47-
self.empty_frame = DataFrame()
48-
self.frame = _frame.copy()
49-
self.frame2 = _frame2.copy()
5046
self.intframe = _intframe.copy()
5147
self.tsframe = _tsframe.copy()
5248
self.mixed_frame = _mixed_frame.copy()
5349
self.categorical = _cat_frame.copy()
5450

5551
yield
5652

57-
del self.empty_frame
58-
59-
del self.frame
60-
del self.frame2
6153
del self.intframe
6254
del self.tsframe
6355
del self.mixed_frame
@@ -126,19 +118,19 @@ def test_frame_non_unique_columns_raises(self, orient):
126118
with pytest.raises(ValueError, match=msg):
127119
df.to_json(orient=orient)
128120

129-
def test_frame_default_orient(self):
130-
assert self.frame.to_json() == self.frame.to_json(orient="columns")
121+
def test_frame_default_orient(self, float_frame):
122+
assert float_frame.to_json() == float_frame.to_json(orient="columns")
131123

132124
@pytest.mark.parametrize("dtype", [False, float])
133125
@pytest.mark.parametrize("convert_axes", [True, False])
134126
@pytest.mark.parametrize("numpy", [True, False])
135-
def test_roundtrip_simple(self, orient, convert_axes, numpy, dtype):
136-
data = self.frame.to_json(orient=orient)
127+
def test_roundtrip_simple(self, orient, convert_axes, numpy, dtype, float_frame):
128+
data = float_frame.to_json(orient=orient)
137129
result = pd.read_json(
138130
data, orient=orient, convert_axes=convert_axes, numpy=numpy, dtype=dtype
139131
)
140132

141-
expected = self.frame.copy()
133+
expected = float_frame
142134

143135
assert_json_roundtrip_equal(result, expected, orient)
144136

@@ -226,12 +218,12 @@ def test_roundtrip_categorical(self, orient, convert_axes, numpy):
226218

227219
@pytest.mark.parametrize("convert_axes", [True, False])
228220
@pytest.mark.parametrize("numpy", [True, False])
229-
def test_roundtrip_empty(self, orient, convert_axes, numpy):
230-
data = self.empty_frame.to_json(orient=orient)
221+
def test_roundtrip_empty(self, orient, convert_axes, numpy, empty_frame):
222+
data = empty_frame.to_json(orient=orient)
231223
result = pd.read_json(
232224
data, orient=orient, convert_axes=convert_axes, numpy=numpy
233225
)
234-
expected = self.empty_frame.copy()
226+
expected = empty_frame.copy()
235227

236228
# TODO: both conditions below are probably bugs
237229
if convert_axes:
@@ -738,11 +730,10 @@ def test_reconstruction_index(self):
738730
result = read_json(df.to_json())
739731
tm.assert_frame_equal(result, df)
740732

741-
def test_path(self):
733+
def test_path(self, float_frame):
742734
with tm.ensure_clean("test.json") as path:
743735
for df in [
744-
self.frame,
745-
self.frame2,
736+
float_frame,
746737
self.intframe,
747738
self.tsframe,
748739
self.mixed_frame,

pandas/tests/resample/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ def frame(index, _series_name, _static_values):
153153

154154

155155
@pytest.fixture
156-
def empty_frame(series):
156+
def empty_frame_dti(series):
157157
"""
158158
Fixture for parametrization of empty DataFrame with date_range,
159159
period_range and timedelta_range indexes

pandas/tests/resample/test_base.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,9 @@ def test_resample_count_empty_series(freq, empty_series_dti, resample_method):
127127

128128
@all_ts
129129
@pytest.mark.parametrize("freq", ["M", "D", "H"])
130-
def test_resample_empty_dataframe(empty_frame, freq, resample_method):
130+
def test_resample_empty_dataframe(empty_frame_dti, freq, resample_method):
131131
# GH13212
132-
df = empty_frame
132+
df = empty_frame_dti
133133
# count retains dimensions too
134134
result = getattr(df.resample(freq), resample_method)()
135135
if resample_method != "size":
@@ -149,15 +149,14 @@ def test_resample_empty_dataframe(empty_frame, freq, resample_method):
149149

150150
@all_ts
151151
@pytest.mark.parametrize("freq", ["M", "D", "H"])
152-
def test_resample_count_empty_dataframe(freq, empty_frame):
152+
def test_resample_count_empty_dataframe(freq, empty_frame_dti):
153153
# GH28427
154154

155-
empty_frame = empty_frame.copy()
156-
empty_frame["a"] = []
155+
empty_frame_dti["a"] = []
157156

158-
result = empty_frame.resample(freq).count()
157+
result = empty_frame_dti.resample(freq).count()
159158

160-
index = _asfreq_compat(empty_frame.index, freq)
159+
index = _asfreq_compat(empty_frame_dti.index, freq)
161160

162161
expected = pd.DataFrame({"a": []}, dtype="int64", index=index)
163162

@@ -166,15 +165,14 @@ def test_resample_count_empty_dataframe(freq, empty_frame):
166165

167166
@all_ts
168167
@pytest.mark.parametrize("freq", ["M", "D", "H"])
169-
def test_resample_size_empty_dataframe(freq, empty_frame):
168+
def test_resample_size_empty_dataframe(freq, empty_frame_dti):
170169
# GH28427
171170

172-
empty_frame = empty_frame.copy()
173-
empty_frame["a"] = []
171+
empty_frame_dti["a"] = []
174172

175-
result = empty_frame.resample(freq).size()
173+
result = empty_frame_dti.resample(freq).size()
176174

177-
index = _asfreq_compat(empty_frame.index, freq)
175+
index = _asfreq_compat(empty_frame_dti.index, freq)
178176

179177
expected = pd.Series([], dtype="int64", index=index)
180178

0 commit comments

Comments
 (0)