Skip to content

Commit 1a36f56

Browse files
committed
fix honor orgin in asfreq
1 parent cc40732 commit 1a36f56

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

doc/source/whatsnew/v3.0.0.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,6 +1059,7 @@ Groupby/resample/rolling
10591059
- Bug in :meth:`.Resampler.interpolate` on a :class:`DataFrame` with non-uniform sampling and/or indices not aligning with the resulting resampled index would result in wrong interpolation (:issue:`21351`)
10601060
- Bug in :meth:`.Series.rolling` when used with a :class:`.BaseIndexer` subclass and computing min/max (:issue:`46726`)
10611061
- Bug in :meth:`DataFrame.ewm` and :meth:`Series.ewm` when passed ``times`` and aggregation functions other than mean (:issue:`51695`)
1062+
- Bug in :meth:`DataFrame.resample.asfreq` where fixed-frequency indexes with ``origin`` ignored alignment and returned incorrect values. Now ``origin`` and ``offset`` are respected. (:issue:`62725`)
10621063
- Bug in :meth:`DataFrame.resample` and :meth:`Series.resample` were not keeping the index name when the index had :class:`ArrowDtype` timestamp dtype (:issue:`61222`)
10631064
- Bug in :meth:`DataFrame.resample` changing index type to :class:`MultiIndex` when the dataframe is empty and using an upsample method (:issue:`55572`)
10641065
- Bug in :meth:`DataFrameGroupBy.agg` and :meth:`SeriesGroupBy.agg` that was returning numpy dtype values when input values are pyarrow dtype values, instead of returning pyarrow dtype values. (:issue:`53030`)

pandas/core/resample.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1889,11 +1889,12 @@ def _upsample(self, method, limit: int | None = None, fill_value=None):
18891889
binner = self.binner
18901890
res_index = self._adjust_binner_for_upsample(binner)
18911891

1892-
# if we have the same frequency as our axis, then we are equal sampling
1892+
# if index exactly matches target grid (same freq & alignment), use fast path
18931893
if (
18941894
limit is None
18951895
and to_offset(ax.inferred_freq) == self.freq
18961896
and len(obj) == len(res_index)
1897+
and obj.index.equals(res_index)
18971898
):
18981899
result = obj.copy()
18991900
result.index = res_index

pandas/tests/resample/test_resample_api.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -989,3 +989,25 @@ def test_resample_empty():
989989
)
990990
result = df.resample("8h").mean()
991991
tm.assert_frame_equal(result, expected)
992+
993+
994+
def test_asfreq_respects_origin_with_fixed_freq_all_seconds_equal():
995+
idx = [
996+
datetime(2025, 10, 17, 17, 15, 10),
997+
datetime(2025, 10, 17, 17, 16, 10),
998+
datetime(2025, 10, 17, 17, 17, 10),
999+
]
1000+
df = DataFrame({"value": [0, 1, 2]}, index=idx)
1001+
1002+
result = df.resample("1min", origin="start_day").asfreq()
1003+
1004+
exp_idx = pd.to_datetime(
1005+
[
1006+
"2025-10-17 17:15:00",
1007+
"2025-10-17 17:16:00",
1008+
"2025-10-17 17:17:00",
1009+
]
1010+
).astype(result.index.dtype) # match time unit (s/us/ns)
1011+
1012+
exp = DataFrame({"value": [np.nan, np.nan, np.nan]}, index=exp_idx)
1013+
tm.assert_frame_equal(result, exp, check_freq=False)

0 commit comments

Comments
 (0)