Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Starting month ignored by resample #59547

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pandas/_libs/tslibs/offsets.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@ cdef class BaseOffset:
"""
dt = Timestamp(dt)
if not self.is_on_offset(dt):
dt = dt - type(self)(1, normalize=self.normalize, **self.kwds)
dt = dt - type(self)(self.n, normalize=self.normalize, **self.kwds)
return dt

def rollforward(self, dt) -> datetime:
Expand All @@ -670,7 +670,7 @@ cdef class BaseOffset:
"""
dt = Timestamp(dt)
if not self.is_on_offset(dt):
dt = dt + type(self)(1, normalize=self.normalize, **self.kwds)
dt = dt + type(self)(self.n, normalize=self.normalize, **self.kwds)
return dt

def _get_offset_day(self, other: datetime) -> int:
Expand Down
23 changes: 23 additions & 0 deletions pandas/tests/resample/test_datetime_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -2020,6 +2020,29 @@ def test_resample_empty_series_with_tz():
tm.assert_series_equal(result, expected)


def test_resample_quarters_non_unitary():
# https://github.com/pandas-dev/pandas/issues/29576

d = Series(
data=np.zeros(365), index=date_range("1950-01-01", "1950-12-31", freq="D")
)

actual = d.resample("2QS-MAR").mean()
expected_idx = DatetimeIndex(
np.array(
[
"1949-09-01",
"1950-03-01",
"1950-09-01",
]
).astype("datetime64[ns]"),
freq="2QS-MAR",
)
expected = Series(0.0, index=expected_idx)

tm.assert_series_equal(expected, actual)


@pytest.mark.parametrize("freq", ["2M", "2m", "2Q", "2Q-SEP", "2q-sep", "1Y", "2Y-MAR"])
def test_resample_M_Q_Y_raises(freq):
msg = f"Invalid frequency: {freq}"
Expand Down
Loading