Pandas version checks

  • [x] I have checked that this issue has not already been reported.

  • [x] I have confirmed this bug exists on the latest version of pandas.

  • [ ] I have confirmed this bug exists on the main branch of pandas.

Reproducible Example

import datetime as dt

import pandas as pd

end = dt.datetime(2025, 7, 26, 6)  # Saturday early morning
for d in range(18, 22):  # Friday, Saturday, Sunday & Monday
    start = dt.datetime(2025, 7, d, 10)
    print(f"start={start}: {pd.date_range(start, end, freq="B")}\n")

Issue Description

Running date_range with varying start and fixed end gives outputs differing final entries when freq="B". Specifically, in the above example, the first and last iteration are missing an entry for 2025-07-25 10:00:00.

Expected Behavior

The last three iterations in the above code should produce the same output, and the first iteration should differ from the other three only in that it additionally includes 2025-07-18 10:00:00 as a first entry. Instead the output is the following:

start=2025-07-18 10:00:00: DatetimeIndex(['2025-07-18 10:00:00', '2025-07-21 10:00:00',
               '2025-07-22 10:00:00', '2025-07-23 10:00:00',
               '2025-07-24 10:00:00'],
              dtype='datetime64[ns]', freq='B')

start=2025-07-19 10:00:00: DatetimeIndex(['2025-07-21 10:00:00', '2025-07-22 10:00:00',
               '2025-07-23 10:00:00', '2025-07-24 10:00:00',
               '2025-07-25 10:00:00'],
              dtype='datetime64[ns]', freq='B')

start=2025-07-20 10:00:00: DatetimeIndex(['2025-07-21 10:00:00', '2025-07-22 10:00:00',
               '2025-07-23 10:00:00', '2025-07-24 10:00:00',
               '2025-07-25 10:00:00'],
              dtype='datetime64[ns]', freq='B')

start=2025-07-21 10:00:00: DatetimeIndex(['2025-07-21 10:00:00', '2025-07-22 10:00:00',
               '2025-07-23 10:00:00', '2025-07-24 10:00:00'],
              dtype='datetime64[ns]', freq='B')

Installed Versions

INSTALLED VERSIONS ------------------ commit : 0691c5cf90477d3503834d983f69350f250a6ff7 python : 3.12.9 python-bits : 64 OS : Linux OS-release : 4.18.0-553.36.1.el8_10.x86_64 Version : #1 SMP Wed Jan 22 03:07:54 EST 2025 machine : x86_64 processor : x86_64 byteorder : little LC_ALL : None LANG : en_US.UTF-8 LOCALE : en_US.UTF-8 pandas : 2.2.3 numpy : 2.1.3 pytz : 2024.1 dateutil : 2.9.0.post0 pip : 25.0.1 Cython : None sphinx : None IPython : 9.1.0 adbc-driver-postgresql: None adbc-driver-sqlite : None bs4 : 4.13.3 blosc : None bottleneck : None dataframe-api-compat : None fastparquet : None fsspec : 2025.3.2 html5lib : None hypothesis : None gcsfs : None jinja2 : 3.1.6 lxml.etree : 5.3.2 matplotlib : 3.10.1 numba : 0.61.0 numexpr : 2.10.2 odfpy : None openpyxl : 3.1.5 pandas_gbq : None psycopg2 : 2.9.9 pymysql : None pyarrow : 17.0.0 pyreadstat : None pytest : 8.3.5 python-calamine : None pyxlsb : None s3fs : 2025.3.2 scipy : 1.15.2 sqlalchemy : 2.0.40 tables : 3.10.2 tabulate : 0.9.0 xarray : None xlrd : None xlsxwriter : None zstandard : 0.23.0 tzdata : 2025.2 qtpy : None pyqt5 : None

Comment From: torext

It looks like this very old issue https://github.com/pandas-dev/pandas/issues/35342 might be related to this, as in addition to the example I gave above I've observed other variations of it where the output is expected etc.

Comment From: rhshadrach

Thanks for the report! I am seeing all end on 2025-07-25 10:00:00 on main. There are a number of fixes in this regard coming in 3.0; closing.