def test_resample_count_empty_series(freq, empty_series_dti, resample_method): # GH28427 result = getattr(empty_series_dti.resample(freq), resample_method)() index = _asfreq_compat(empty_series_dti.index, freq) expected = Series([], dtype="int64", index=index, name=empty_series_dti.name) tm.assert_series_equal(result, expected)
def test_resample_size_empty_dataframe(freq, empty_frame_dti): # GH28427 empty_frame_dti["a"] = [] result = empty_frame_dti.resample(freq).size() index = _asfreq_compat(empty_frame_dti.index, freq) expected = pd.Series([], dtype="int64", index=index) tm.assert_series_equal(result, expected)
def test_resample_count_empty_dataframe(freq, empty_frame_dti): # GH28427 empty_frame_dti["a"] = [] result = empty_frame_dti.resample(freq).count() index = _asfreq_compat(empty_frame_dti.index, freq) expected = pd.DataFrame({"a": []}, dtype="int64", index=index) tm.assert_frame_equal(result, expected)
def test_resample_empty_series(freq, empty_series_dti, resample_method): # GH12771 & GH12868 if resample_method == "ohlc": pytest.skip("need to test for ohlc from GH13083") s = empty_series_dti result = getattr(s.resample(freq), resample_method)() expected = s.copy() expected.index = _asfreq_compat(s.index, freq) tm.assert_index_equal(result.index, expected.index) assert result.index.freq == expected.index.freq tm.assert_series_equal(result, expected, check_dtype=False)
def test_resample_empty_dataframe(empty_frame_dti, freq, resample_method): # GH13212 df = empty_frame_dti # count retains dimensions too result = getattr(df.resample(freq), resample_method)() if resample_method != "size": expected = df.copy() else: # GH14962 expected = Series([], dtype=object) expected.index = _asfreq_compat(df.index, freq) tm.assert_index_equal(result.index, expected.index) assert result.index.freq == expected.index.freq tm.assert_almost_equal(result, expected, check_dtype=False)
def test_resample_empty_series(freq, empty_series_dti, resample_method, request): # GH12771 & GH12868 if resample_method == "ohlc" and isinstance(empty_series_dti.index, PeriodIndex): request.node.add_marker( pytest.mark.xfail( reason=f"GH13083: {resample_method} fails for PeriodIndex")) ser = empty_series_dti result = getattr(ser.resample(freq), resample_method)() expected = ser.copy() expected.index = _asfreq_compat(ser.index, freq) tm.assert_index_equal(result.index, expected.index) assert result.index.freq == expected.index.freq tm.assert_series_equal(result, expected, check_dtype=False)