Skip to content
Prev Previous commit
Next Next commit
create empty_frame fixture
  • Loading branch information
simonjayhawkins committed Dec 22, 2018
commit 3a8d8b1aac4b10d4223a95a2a4620cf5b83c5c10
6 changes: 6 additions & 0 deletions pandas/tests/resample/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ def frame(index, _series_name, _static_values):
return DataFrame({'value': _static_values}, index=index)


@pytest.fixture
def empty_frame(series):
index = series.index[:0]
return DataFrame(index=index)


@pytest.fixture(params=[Series, DataFrame])
def series_and_frame(request, series, frame):
if request.param == Series:
Expand Down
12 changes: 5 additions & 7 deletions pandas/tests/resample/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,20 +111,18 @@ def test_resample_empty_series_all_ts(freq, empty_series, resample_method):


@pytest.mark.parametrize('freq', ['M', 'D', 'H'])
def test_resample_empty_dataframe_all_ts(series, freq, resample_method):
def test_resample_empty_dataframe_all_ts(empty_frame, freq, resample_method):
# GH13212
index = series.index[:0]
f = DataFrame(index=index)

df = empty_frame
# count retains dimensions too
result = getattr(f.resample(freq), resample_method)()
result = getattr(df.resample(freq), resample_method)()
if resample_method != 'size':
expected = f.copy()
expected = df.copy()
else:
# GH14962
expected = Series([])

expected.index = f.index._shallow_copy(freq=freq)
expected.index = df.index._shallow_copy(freq=freq)
assert_index_equal(result.index, expected.index)
assert result.index.freq == expected.index.freq
assert_almost_equal(result, expected, check_dtype=False)
Expand Down