Skip to content

BUG: bdate_range(end, periods, freq=nB) anchors stride at buffer start#65604

Draft
jbrockmendel wants to merge 2 commits into
pandas-dev:mainfrom
jbrockmendel:perf-bdate_range-2
Draft

BUG: bdate_range(end, periods, freq=nB) anchors stride at buffer start#65604
jbrockmendel wants to merge 2 commits into
pandas-dev:mainfrom
jbrockmendel:perf-bdate_range-2

Conversation

@jbrockmendel
Copy link
Copy Markdown
Member

Summary

Follow-up to GH-64648, addressing a regression flagged by @jorisvandenbossche in post-merge review.

When bdate_range / date_range is called with end + periods and freq="nB" (or "nC") where n >= 2, the new fast path in generate_daily_offset_range anchored the [::n] stride at the start of the internal buffer instead of at end. The result was offset by buffer_days % n:

>>> pd.bdate_range(end="2026-03-22", periods=3, freq="2B")
# main (before fix):  ['2026-03-13', '2026-03-17', '2026-03-19']
# expected / 3.0.x:   ['2026-03-16', '2026-03-18', '2026-03-20']

n=1 was unaffected. Only n>=2 with end+periods is broken.

The fix reverses the array before striding so the anchor is the last on-offset date <= end, then reverses back. Symmetric with the existing trim_from_end branch a few lines later.

This regression only exists on main — 3.0.x doesn't have GH-64648 and uses the old _generate_range path, which handles nB correctly. No 3.1.0 has been released yet, so no whatsnew entry.

Test plan

  • New parametrized regression test covering end on Fri/Sat/Sun with freq="2B" and "3B"
  • Full pandas/tests/indexes/datetimes/test_date_range.py (421 tests) passes
  • Full pandas/tests/tseries/ (6941 tests) passes
  • mypy and pre-commit clean

🤖 Generated with Claude Code

jbrockmendel and others added 2 commits May 11, 2026 13:08
…buffer

Follow-up to pandas-devGH-64648: when end + periods are given and freq is n*B
(or n*C) with n >= 2, the [::abs_n] stride was anchored at the start
of the internal buffer instead of at end, producing dates offset by
(buffer_days % n). Reverse before striding so the anchor is the last
on-offset date <= end.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@jorisvandenbossche jorisvandenbossche added this to the 3.1 milestone May 12, 2026
@jorisvandenbossche
Copy link
Copy Markdown
Member

Thanks, looks good to me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants