Skip to content

Commit 7a425e6

Browse files
committed
update test
1 parent e51514b commit 7a425e6

File tree

1 file changed

+25
-47
lines changed

1 file changed

+25
-47
lines changed

pandas/tests/resample/test_base.py

+25-47
Original file line numberDiff line numberDiff line change
@@ -273,66 +273,44 @@ def test_resample_quantile(series):
273273
"_index_factory,_series_name,_index_start,_index_end", [DATE_RANGE, PERIOD_RANGE]
274274
)
275275
@pytest.mark.parametrize(
276-
"freq, result_dict",
276+
"freq, result_data, result_index, result_freq",
277277
[
278278
(
279279
"D",
280-
{
281-
"dti": {
282-
"data": [1.0] * 5 + [np.nan] * 5,
283-
"index": DatetimeIndex(
284-
["2005-01-{}".format(i) for i in range(1, 11)], freq="D"
285-
),
286-
},
287-
"pi": {
288-
"data": [1.0] * 5 + [np.nan] * 5,
289-
"index": PeriodIndex(
290-
["2005-01-{}".format(i) for i in range(1, 11)], freq="D"
291-
),
292-
},
293-
},
280+
[1.0] * 5 + [np.nan] * 5,
281+
["2005-01-{}".format(i) for i in range(1, 11)],
282+
"D",
294283
),
295284
(
296-
"W",
297-
{
298-
"dti": {
299-
"data": [2.0, 3.0, np.nan],
300-
"index": DatetimeIndex(
301-
["2005-01-02", "2005-01-09", "2005-01-16"], freq="W-SUN"
302-
),
303-
},
304-
"pi": {
305-
"data": [2.0, 3.0, np.nan],
306-
"index": PeriodIndex(
307-
[
308-
"2004-12-27/2005-01-02",
309-
"2005-01-03/2005-01-09",
310-
"2005-01-10/2005-01-16",
311-
],
312-
freq="W-SUN",
313-
),
314-
},
315-
},
285+
"D",
286+
[1.0] * 5 + [np.nan] * 5,
287+
["2005-01-{}".format(i) for i in range(1, 11)],
288+
"D",
316289
),
290+
("W", [2.0, 3.0, np.nan], ["2005-01-02", "2005-01-09", "2005-01-16"], "W-SUN"),
317291
(
318-
"M",
319-
{
320-
"dti": {
321-
"data": [5.0],
322-
"index": DatetimeIndex(["2005-01-31"], freq="M"),
323-
},
324-
"pi": {"data": [5.0], "index": PeriodIndex(["2005-01"], freq="M")},
325-
},
292+
"W",
293+
[2.0, 3.0, np.nan],
294+
["2004-12-27/2005-01-02", "2005-01-03/2005-01-09", "2005-01-10/2005-01-16"],
295+
"W-SUN",
326296
),
297+
("M", [5.0], ["2005-01-31"], "M"),
298+
("M", [5.0], ["2005-01"], "M"),
327299
],
328300
)
329-
def test_resample_sum(series, freq, result_dict):
301+
def test_resample_sum(series, freq, result_data, result_index, result_freq):
330302
# GH 19974
331303
series[:5] = 1
332304
series[5:] = np.nan
333305
result = series.resample(freq).sum(min_count=1)
334306

335-
key = result.name
336-
index = result_dict[key]["index"]
337-
expected = Series(result_dict[key]["data"], index, name=key)
307+
result_name = result.name
308+
if isinstance(series.index, DatetimeIndex) and result_name == "dti":
309+
index = DatetimeIndex(result_index, freq=result_freq)
310+
elif isinstance(series.index, PeriodIndex) and result_name == "pi":
311+
index = PeriodIndex(result_index, freq=result_freq)
312+
else:
313+
pytest.skip("unsupported configuration")
314+
315+
expected = Series(result_data, index, name=result_name)
338316
tm.assert_series_equal(result, expected)

0 commit comments

Comments
 (0)