From 22fced1d74e81e8a1bc1417ab72ed275441e22bc Mon Sep 17 00:00:00 2001 From: Con Date: Thu, 29 Jun 2023 16:36:59 -0400 Subject: [PATCH 1/9] add missing origin check --- pandas/core/resample.py | 8 +++++++- pandas/tests/resample/test_datetime_index.py | 17 +++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/pandas/core/resample.py b/pandas/core/resample.py index 9566a2f113b36..fd6a94dff441b 100644 --- a/pandas/core/resample.py +++ b/pandas/core/resample.py @@ -2201,7 +2201,13 @@ def _get_timestamp_range_edges( last = last.normalize() if closed == "left": - first = Timestamp(freq.rollback(first)) + if isinstance(origin, Timestamp): + if first - freq >= origin: + first = Timestamp(first - freq) + else: + first = Timestamp(freq.rollback(first)) + else: + first = Timestamp(freq.rollback(first)) else: first = Timestamp(first - freq) diff --git a/pandas/tests/resample/test_datetime_index.py b/pandas/tests/resample/test_datetime_index.py index 0f52f2d1c65ee..f1f5b6749036f 100644 --- a/pandas/tests/resample/test_datetime_index.py +++ b/pandas/tests/resample/test_datetime_index.py @@ -838,6 +838,23 @@ def test_resample_bad_offset(offset, unit): ts.resample("5min", offset=offset) +def test_resample_monthstart_origin(): + # GH 53662 + df = DataFrame({"ts": [datetime(1999, 12, 31, 0, 0, 0)], "values": [10.0]}) + + result = df.resample("2MS", on="ts", origin="1999-11-01", closed="right")[ + "values" + ].sum() + excepted = Series( + [10.0], + index=DatetimeIndex( + ["1999-11-01"], dtype="datetime64[ns]", name="ts", freq="2MS" + ), + ) + + tm.assert_index_equal(result.index, excepted.index) + + def test_resample_origin_prime_freq(unit): # GH 31809 start, end = "2000-10-01 23:30:00", "2000-10-02 00:30:00" From aa4fe97bcdcae1df203251eea3aa7eb043c3ac6d Mon Sep 17 00:00:00 2001 From: Con Date: Thu, 29 Jun 2023 16:49:29 -0400 Subject: [PATCH 2/9] whats new --- doc/source/whatsnew/v2.1.0.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/source/whatsnew/v2.1.0.rst b/doc/source/whatsnew/v2.1.0.rst index a51b2d1855e71..fd15306f73344 100644 --- a/doc/source/whatsnew/v2.1.0.rst +++ b/doc/source/whatsnew/v2.1.0.rst @@ -475,6 +475,7 @@ Plotting Groupby/resample/rolling ^^^^^^^^^^^^^^^^^^^^^^^^ +- Bug in :meth:`DataFrame.resample` and :meth:`Series.resample` :class:`Datetimelike` ``origin`` has no effect in resample for ``MS`` frequency (:issue:`53662`) - Bug in :meth:`DataFrame.resample` and :meth:`Series.resample` in incorrectly allowing non-fixed ``freq`` when resampling on a :class:`TimedeltaIndex` (:issue:`51896`) - Bug in :meth:`DataFrame.resample` and :meth:`Series.resample` losing time zone when resampling empty data (:issue:`53664`) - Bug in :meth:`DataFrameGroupBy.idxmin`, :meth:`SeriesGroupBy.idxmin`, :meth:`DataFrameGroupBy.idxmax`, :meth:`SeriesGroupBy.idxmax` return wrong dtype when used on empty DataFrameGroupBy or SeriesGroupBy (:issue:`51423`) From 0093c414b0202aa0e6320252d66a03cfe8003f93 Mon Sep 17 00:00:00 2001 From: Conrad Date: Mon, 10 Jul 2023 10:59:33 -0400 Subject: [PATCH 3/9] resolve edge cases, fix tests --- pandas/core/resample.py | 22 ++++---- pandas/tests/resample/test_datetime_index.py | 54 ++++++++++++------- .../tests/resample/test_resampler_grouper.py | 32 ++++++----- 3 files changed, 68 insertions(+), 40 deletions(-) diff --git a/pandas/core/resample.py b/pandas/core/resample.py index 72662a1818c5e..d2e76a4c27236 100644 --- a/pandas/core/resample.py +++ b/pandas/core/resample.py @@ -2438,8 +2438,15 @@ def _get_timestamp_range_edges( """ if isinstance(freq, Tick): index_tz = first.tz - if isinstance(origin, Timestamp) and (origin.tz is None) != (index_tz is None): - raise ValueError("The origin must have the same timezone as the index.") + if isinstance(origin, Timestamp) and origin.tz != index_tz: + if first.utcoffset() != origin.utcoffset(): + raise ValueError("The origin must have the same timezone as the index.") + elif isinstance(origin, Timestamp): + if origin <= first: + first = origin + elif origin >= last: + last = origin + if origin == "epoch": # set the epoch based on the timezone to have similar bins results when # resampling on the same kind of indexes on different timezones @@ -2461,17 +2468,14 @@ def _get_timestamp_range_edges( first = first.tz_localize(index_tz) last = last.tz_localize(index_tz) else: + if isinstance(origin, Timestamp): + first = origin + first = first.normalize() last = last.normalize() if closed == "left": - if isinstance(origin, Timestamp): - if first - freq >= origin: - first = Timestamp(first - freq) - else: - first = Timestamp(freq.rollback(first)) - else: - first = Timestamp(freq.rollback(first)) + first = Timestamp(freq.rollback(first)) else: first = Timestamp(first - freq) diff --git a/pandas/tests/resample/test_datetime_index.py b/pandas/tests/resample/test_datetime_index.py index 2097ae34ac649..887b57e52b6ec 100644 --- a/pandas/tests/resample/test_datetime_index.py +++ b/pandas/tests/resample/test_datetime_index.py @@ -791,24 +791,34 @@ def test_resample_offset(unit): @pytest.mark.parametrize( - "kwargs", + "kwargs, expected", [ - {"origin": "1999-12-31 23:57:00"}, - {"origin": Timestamp("1970-01-01 00:02:00")}, - {"origin": "epoch", "offset": "2m"}, + ( + {"origin": "1999-12-31 23:57:00"}, + ["1999-12-31 23:57:00", "2000-01-01 01:57:00"], + ), + ( + {"origin": Timestamp("1970-01-01 00:02:00")}, + ["1970-01-01 00:02:00", "2000-01-01 01:57:00"], + ), + ( + {"origin": "epoch", "offset": "2m"}, + ["1999-12-31 23:57:00", "2000-01-01 01:57:00"], + ), # origin of '1999-31-12 12:02:00' should be equivalent for this case - {"origin": "1999-12-31 12:02:00"}, - {"offset": "-3m"}, + ( + {"origin": "1999-12-31 12:02:00"}, + ["1999-12-31 12:02:00", "2000-01-01 01:57:00"], + ), + ({"offset": "-3m"}, ["1999-12-31 23:57:00", "2000-01-01 01:57:00"]), ], ) -def test_resample_origin(kwargs, unit): +def test_resample_origin(kwargs, unit, expected): # GH 31809 rng = date_range("2000-01-01 00:00:00", "2000-01-01 02:00", freq="s").as_unit(unit) ts = Series(np.random.randn(len(rng)), index=rng) - exp_rng = date_range( - "1999-12-31 23:57:00", "2000-01-01 01:57", freq="5min" - ).as_unit(unit) + exp_rng = date_range(expected[0], expected[1], freq="5min").as_unit(unit) resampled = ts.resample("5min", **kwargs).mean() tm.assert_index_equal(resampled.index, exp_rng) @@ -841,19 +851,27 @@ def test_resample_bad_offset(offset, unit): def test_resample_monthstart_origin(): # GH 53662 df = DataFrame({"ts": [datetime(1999, 12, 31, 0, 0, 0)], "values": [10.0]}) - - result = df.resample("2MS", on="ts", origin="1999-11-01", closed="right")[ - "values" - ].sum() + result = df.resample("2MS", on="ts", origin="1999-11-01")["values"].sum() excepted = Series( [10.0], index=DatetimeIndex( ["1999-11-01"], dtype="datetime64[ns]", name="ts", freq="2MS" ), ) - tm.assert_index_equal(result.index, excepted.index) + df = DataFrame({"ts": [datetime(1999, 12, 31, 20)], "values": [10.0]}) + result = df.resample( + "3YS", on="ts", closed="left", label="left", origin=datetime(1995, 1, 1) + )["values"].sum() + expected = Series( + [0, 10.0], + index=DatetimeIndex( + ["1995-01-01", "1998-01-01"], dtype="datetime64[ns]", name="ts", freq="3YS" + ), + ) + tm.assert_index_equal(result.index, expected.index) + def test_resample_origin_prime_freq(unit): # GH 31809 @@ -886,7 +904,7 @@ def test_resample_origin_prime_freq(unit): tm.assert_index_equal(resampled.index, exp_rng) exp_rng = date_range( - "2000-10-01 23:24:00", "2000-10-02 00:15:00", freq="17min" + "2000-01-01 00:00:00", "2000-10-02 00:15:00", freq="17min" ).as_unit(unit) resampled = ts.resample("17min", origin="2000-01-01").mean() tm.assert_index_equal(resampled.index, exp_rng) @@ -905,11 +923,11 @@ def test_resample_origin_with_tz(unit): exp_rng = date_range( "1999-12-31 23:57:00", "2000-01-01 01:57", freq="5min", tz=tz ).as_unit(unit) - resampled = ts.resample("5min", origin="1999-12-31 23:57:00+00:00").mean() + resampled = ts.resample("5min", origin="1999-12-31 23:57:00+01:00").mean() tm.assert_index_equal(resampled.index, exp_rng) # origin of '1999-31-12 12:02:00+03:00' should be equivalent for this case - resampled = ts.resample("5min", origin="1999-12-31 12:02:00+03:00").mean() + resampled = ts.resample("5min", origin="1999-12-31 12:02:00+01:00").mean() tm.assert_index_equal(resampled.index, exp_rng) resampled = ts.resample("5min", origin="epoch", offset="2m").mean() diff --git a/pandas/tests/resample/test_resampler_grouper.py b/pandas/tests/resample/test_resampler_grouper.py index df14a5bc374c6..5c5cadc3bc6e4 100644 --- a/pandas/tests/resample/test_resampler_grouper.py +++ b/pandas/tests/resample/test_resampler_grouper.py @@ -141,6 +141,19 @@ def test_groupby_with_origin(): start, end = "1/1/2000 00:00:00", "1/31/2000 00:00" middle = "1/15/2000 00:00:00" + # test origin on 1970-01-01 00:00:00 + rng = date_range("1970-01-01 00:00:00", end, freq="1231min") # prime number + ts = Series(np.random.randn(len(rng)), index=rng) + middle_ts = rng[len(rng) // 2] + ts2 = ts[middle_ts:end] + + origin = Timestamp(0) + adjusted_grouper = pd.Grouper(freq=freq, origin=origin) + adjusted_count_ts = ts.groupby(adjusted_grouper).agg("count") + adjusted_count_ts = adjusted_count_ts[middle_ts:end] + adjusted_count_ts2 = ts2.groupby(adjusted_grouper).agg("count") + tm.assert_series_equal(adjusted_count_ts, adjusted_count_ts2[middle_ts:end]) + rng = date_range(start, end, freq="1231min") # prime number ts = Series(np.random.randn(len(rng)), index=rng) ts2 = ts[middle:end] @@ -154,26 +167,19 @@ def test_groupby_with_origin(): with pytest.raises(AssertionError, match="Index are different"): tm.assert_index_equal(count_ts.index, count_ts2.index) - # test origin on 1970-01-01 00:00:00 - origin = Timestamp(0) - adjusted_grouper = pd.Grouper(freq=freq, origin=origin) - adjusted_count_ts = ts.groupby(adjusted_grouper).agg("count") - adjusted_count_ts = adjusted_count_ts[middle:end] - adjusted_count_ts2 = ts2.groupby(adjusted_grouper).agg("count") - tm.assert_series_equal(adjusted_count_ts, adjusted_count_ts2) - # test origin on 2049-10-18 20:00:00 + + rng = date_range(start, "2049-10-18 20:00:00", freq="1231min") # prime number + ts = Series(np.random.randn(len(rng)), index=rng) + middle_ts = rng[len(rng) // 2] + ts2 = ts[middle_ts:end] origin_future = Timestamp(0) + pd.Timedelta("1399min") * 30_000 adjusted_grouper2 = pd.Grouper(freq=freq, origin=origin_future) adjusted2_count_ts = ts.groupby(adjusted_grouper2).agg("count") - adjusted2_count_ts = adjusted2_count_ts[middle:end] + adjusted2_count_ts = adjusted2_count_ts[middle_ts:end] adjusted2_count_ts2 = ts2.groupby(adjusted_grouper2).agg("count") tm.assert_series_equal(adjusted2_count_ts, adjusted2_count_ts2) - # both grouper use an adjusted timestamp that is a multiple of 1399 min - # they should be equals even if the adjusted_timestamp is in the future - tm.assert_series_equal(adjusted_count_ts, adjusted2_count_ts2) - def test_nearest(): # GH 17496 From 846cb23ec869867ca9ffdd7ad461d7839eca642a Mon Sep 17 00:00:00 2001 From: Conrad Date: Wed, 12 Jul 2023 13:33:32 -0400 Subject: [PATCH 4/9] update docs --- pandas/core/generic.py | 7 +++++++ pandas/core/groupby/grouper.py | 9 ++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 42cd74a0ca781..106c6b3cc0310 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -9223,6 +9223,13 @@ def resample( Freq: 17T, dtype: int64 >>> ts.resample('17min', origin='2000-01-01').sum() + 2000-01-01 00:00:00 0 + 2000-01-01 00:17:00 0 + 2000-01-01 00:34:00 0 + 2000-01-01 00:51:00 0 + 2000-01-01 01:08:00 0 + .. + 2000-10-01 23:07:00 0 2000-10-01 23:24:00 3 2000-10-01 23:41:00 15 2000-10-01 23:58:00 45 diff --git a/pandas/core/groupby/grouper.py b/pandas/core/groupby/grouper.py index 764b74f81e7ef..96e31a85ede75 100644 --- a/pandas/core/groupby/grouper.py +++ b/pandas/core/groupby/grouper.py @@ -207,11 +207,18 @@ class Grouper: Freq: 17T, dtype: int64 >>> ts.groupby(pd.Grouper(freq='17min', origin='2000-01-01')).sum() + 2000-01-01 00:00:00 0 + 2000-01-01 00:17:00 0 + 2000-01-01 00:34:00 0 + 2000-01-01 00:51:00 0 + 2000-01-01 01:08:00 0 + .. + 2000-10-01 23:07:00 0 2000-10-01 23:24:00 3 2000-10-01 23:41:00 15 2000-10-01 23:58:00 45 2000-10-02 00:15:00 45 - Freq: 17T, dtype: int64 + Freq: 17T, Length: 23296, dtype: int64 If you want to adjust the start of the bins with an `offset` Timedelta, the two following lines are equivalent: From ace5a03484433c7c0fdaeecb717aec805d5ba815 Mon Sep 17 00:00:00 2001 From: Conrad Date: Wed, 12 Jul 2023 14:38:02 -0400 Subject: [PATCH 5/9] cleanup --- pandas/core/generic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 106c6b3cc0310..cfe4ce37728a5 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -9234,7 +9234,7 @@ def resample( 2000-10-01 23:41:00 15 2000-10-01 23:58:00 45 2000-10-02 00:15:00 45 - Freq: 17T, dtype: int64 + Freq: 17T, Length: 23296, dtype: int64 If you want to adjust the start of the bins with an `offset` Timedelta, the two following lines are equivalent: From 22a7bdf1f45073ee7468f690e89a7f3fb05ff1ee Mon Sep 17 00:00:00 2001 From: Con Date: Thu, 13 Jul 2023 13:10:28 -0400 Subject: [PATCH 6/9] accomidate daylight savings time --- pandas/core/resample.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pandas/core/resample.py b/pandas/core/resample.py index e694e6fa14cec..4069fd29ab245 100644 --- a/pandas/core/resample.py +++ b/pandas/core/resample.py @@ -2457,9 +2457,14 @@ def _get_timestamp_range_edges( """ if isinstance(freq, Tick): index_tz = first.tz + if isinstance(origin, Timestamp) and origin.tz != index_tz: - if first.utcoffset() != origin.utcoffset(): - raise ValueError("The origin must have the same timezone as the index.") + if origin.dst() != first.dst(): + if origin.utcoffset() != first.utcoffset(): + raise ValueError( + "The origin must have the same timezone as the index." + ) + elif isinstance(origin, Timestamp): if origin <= first: first = origin From c5bc32a2965fca0bd26e0f2932b4336874a91f82 Mon Sep 17 00:00:00 2001 From: Conrad Date: Fri, 14 Jul 2023 22:49:59 -0400 Subject: [PATCH 7/9] correct docs and remove nested checks --- doc/source/whatsnew/v2.1.0.rst | 2 +- pandas/core/resample.py | 6 +----- pandas/tests/resample/test_datetime_index.py | 7 ------- 3 files changed, 2 insertions(+), 13 deletions(-) diff --git a/doc/source/whatsnew/v2.1.0.rst b/doc/source/whatsnew/v2.1.0.rst index d7ba4807b0036..2c04eeaea42ae 100644 --- a/doc/source/whatsnew/v2.1.0.rst +++ b/doc/source/whatsnew/v2.1.0.rst @@ -538,7 +538,7 @@ Plotting Groupby/resample/rolling ^^^^^^^^^^^^^^^^^^^^^^^^ -- Bug in :meth:`DataFrame.resample` and :meth:`Series.resample` :class:`Datetimelike` ``origin`` has no effect in resample for ``MS`` frequency (:issue:`53662`) +- Bug in :meth:`DataFrame.resample` and :meth:`Series.resample` :class:`Datetimelike` ``origin`` has no effect in resample when values are outside of axis (:issue:`53662`) - Bug in :meth:`DataFrame.resample` and :meth:`Series.resample` in incorrectly allowing non-fixed ``freq`` when resampling on a :class:`TimedeltaIndex` (:issue:`51896`) - Bug in :meth:`DataFrame.resample` and :meth:`Series.resample` losing time zone when resampling empty data (:issue:`53664`) - Bug in :meth:`DataFrameGroupBy.idxmin`, :meth:`SeriesGroupBy.idxmin`, :meth:`DataFrameGroupBy.idxmax`, :meth:`SeriesGroupBy.idxmax` return wrong dtype when used on empty DataFrameGroupBy or SeriesGroupBy (:issue:`51423`) diff --git a/pandas/core/resample.py b/pandas/core/resample.py index 1b350489dc302..53d587cdde182 100644 --- a/pandas/core/resample.py +++ b/pandas/core/resample.py @@ -2465,11 +2465,7 @@ def _get_timestamp_range_edges( index_tz = first.tz if isinstance(origin, Timestamp) and origin.tz != index_tz: - if origin.dst() != first.dst(): - if origin.utcoffset() != first.utcoffset(): - raise ValueError( - "The origin must have the same timezone as the index." - ) + raise ValueError("The origin must have the same timezone as the index.") elif isinstance(origin, Timestamp): if origin <= first: diff --git a/pandas/tests/resample/test_datetime_index.py b/pandas/tests/resample/test_datetime_index.py index 1ff4a898c993c..ca7cdd42f4bf2 100644 --- a/pandas/tests/resample/test_datetime_index.py +++ b/pandas/tests/resample/test_datetime_index.py @@ -922,13 +922,6 @@ def test_resample_origin_with_tz(unit): exp_rng = date_range( "1999-12-31 23:57:00", "2000-01-01 01:57", freq="5min", tz=tz ).as_unit(unit) - resampled = ts.resample("5min", origin="1999-12-31 23:57:00+01:00").mean() - tm.assert_index_equal(resampled.index, exp_rng) - - # origin of '1999-31-12 12:02:00+03:00' should be equivalent for this case - resampled = ts.resample("5min", origin="1999-12-31 12:02:00+01:00").mean() - tm.assert_index_equal(resampled.index, exp_rng) - resampled = ts.resample("5min", origin="epoch", offset="2m").mean() tm.assert_index_equal(resampled.index, exp_rng) From 845bc0ec1c08dbfc9b72c536a24b061c4b06f735 Mon Sep 17 00:00:00 2001 From: Con Date: Sun, 16 Jul 2023 02:56:56 +0000 Subject: [PATCH 8/9] slim down example --- pandas/core/generic.py | 19 ++++++------------- pandas/core/groupby/grouper.py | 19 ++++++------------- 2 files changed, 12 insertions(+), 26 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 4b69a44114ccf..4b9e2e39f56a2 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -9231,19 +9231,12 @@ def resample( 2000-10-02 00:26:00 24 Freq: 17T, dtype: int64 - >>> ts.resample('17min', origin='2000-01-01').sum() - 2000-01-01 00:00:00 0 - 2000-01-01 00:17:00 0 - 2000-01-01 00:34:00 0 - 2000-01-01 00:51:00 0 - 2000-01-01 01:08:00 0 - .. - 2000-10-01 23:07:00 0 - 2000-10-01 23:24:00 3 - 2000-10-01 23:41:00 15 - 2000-10-01 23:58:00 45 - 2000-10-02 00:15:00 45 - Freq: 17T, Length: 23296, dtype: int64 + >>> ts.resample('17W', origin='2000-01-01').sum() + 2000-01-02 0 + 2000-04-30 0 + 2000-08-27 0 + 2000-12-24 108 + Freq: 17W-SUN, dtype: int64 If you want to adjust the start of the bins with an `offset` Timedelta, the two following lines are equivalent: diff --git a/pandas/core/groupby/grouper.py b/pandas/core/groupby/grouper.py index 96e31a85ede75..ed82ba14e99b7 100644 --- a/pandas/core/groupby/grouper.py +++ b/pandas/core/groupby/grouper.py @@ -206,19 +206,12 @@ class Grouper: 2000-10-02 00:26:00 24 Freq: 17T, dtype: int64 - >>> ts.groupby(pd.Grouper(freq='17min', origin='2000-01-01')).sum() - 2000-01-01 00:00:00 0 - 2000-01-01 00:17:00 0 - 2000-01-01 00:34:00 0 - 2000-01-01 00:51:00 0 - 2000-01-01 01:08:00 0 - .. - 2000-10-01 23:07:00 0 - 2000-10-01 23:24:00 3 - 2000-10-01 23:41:00 15 - 2000-10-01 23:58:00 45 - 2000-10-02 00:15:00 45 - Freq: 17T, Length: 23296, dtype: int64 + >>> ts.groupby(pd.Grouper(freq='17W', origin='2000-01-01')).sum() + 2000-01-02 0 + 2000-04-30 0 + 2000-08-27 0 + 2000-12-24 108 + Freq: 17W-SUN, dtype: int64 If you want to adjust the start of the bins with an `offset` Timedelta, the two following lines are equivalent: From 525bc588b91a4c7928c6af8119581baaf6ce4408 Mon Sep 17 00:00:00 2001 From: Con Date: Sun, 16 Jul 2023 14:21:17 +0000 Subject: [PATCH 9/9] add back tz aware test --- pandas/tests/resample/test_datetime_index.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pandas/tests/resample/test_datetime_index.py b/pandas/tests/resample/test_datetime_index.py index ca7cdd42f4bf2..12e15eab3aa64 100644 --- a/pandas/tests/resample/test_datetime_index.py +++ b/pandas/tests/resample/test_datetime_index.py @@ -925,6 +925,11 @@ def test_resample_origin_with_tz(unit): resampled = ts.resample("5min", origin="epoch", offset="2m").mean() tm.assert_index_equal(resampled.index, exp_rng) + resampled = ts.resample( + "5min", origin=Timestamp("1999-12-31 23:57:00", tz=tz) + ).mean() + tm.assert_index_equal(resampled.index, exp_rng) + with pytest.raises(ValueError, match=msg): ts.resample("5min", origin="12/31/1999 23:57:00").mean()