Skip to content
Merged
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
10 changes: 9 additions & 1 deletion pandas/core/arrays/_ranges.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,15 @@ def generate_daily_offset_range(
i8values = i8values[freq._get_daily_offset_mask(dt64)] # type: ignore[attr-defined]

if abs_n > 1:
i8values = i8values[::abs_n]
# When trimming from the end (end+periods case), the buffer starts
# at an arbitrary date (end - buffer_days), so a forward [::abs_n]
# stride would anchor there. Reverse first so the stride is anchored
# on the last on-offset date <= end, e.g. freq="2B" yields
# ..., last-4, last-2, last business day (GH#64648).
if trim_from_end:
i8values = i8values[::-1][::abs_n][::-1]
else:
i8values = i8values[::abs_n]

if trim_to is not None:
if trim_from_end:
Expand Down
13 changes: 13 additions & 0 deletions pandas/tests/indexes/datetimes/test_date_range.py
Original file line number Diff line number Diff line change
Expand Up @@ -1194,6 +1194,19 @@ def test_bdate_range_end_weekend_periods(self):
result = bdate_range(end="2026-03-22", periods=3)
tm.assert_index_equal(result, expected)

@pytest.mark.parametrize("end", ["2026-03-20", "2026-03-21", "2026-03-22"])
def test_bdate_range_end_periods_multiple_n(self, end):
# GH#64648 (post-merge): with end+periods and freq="nB" (n>=2),
# the on-offset stride must be anchored at the end (last business
# day <= end), not at the start of the internal buffer.
result = bdate_range(end=end, periods=3, freq="2B")
expected = DatetimeIndex(["2026-03-16", "2026-03-18", "2026-03-20"])
tm.assert_index_equal(result, expected)

result = bdate_range(end=end, periods=3, freq="3B")
expected = DatetimeIndex(["2026-03-12", "2026-03-17", "2026-03-20"])
tm.assert_index_equal(result, expected)


class TestCustomDateRange:
def test_constructor(self):
Expand Down
Loading