Description
Pandas version checks
-
I have checked that this issue has not already been reported.
-
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 pandas as pd
from pandas.tseries.offsets import CustomBusinessDay
from datetime import datetime
offset = CustomBusinessDay(weekmask='Sun Mon Tue Wed Thu')
start = datetime(2024, 2, 8, 23)
end = datetime(2024, 2, 16, 14)
d_range = pd.date_range(start, end, freq=offset)
print(d_range)
#DatetimeIndex(['2024-02-08 23:00:00', '2024-02-11 23:00:00',
# '2024-02-12 23:00:00', '2024-02-13 23:00:00',
# '2024-02-14 23:00:00'],
# dtype='datetime64[ns]', freq='C')
start = datetime(2024, 2, 9, 23)
d_range = pd.date_range(start, end, freq=offset)
print(d_range)
#DatetimeIndex(['2024-02-11 23:00:00', '2024-02-12 23:00:00',
# '2024-02-13 23:00:00', '2024-02-14 23:00:00',
# '2024-02-15 23:00:00'],
# dtype='datetime64[ns]', freq='C')
Issue Description
The last date generated from date_range
with start = datetime(2024, 2, 8, 23)
does not equal the last date generated from date_range
when start = datetime(2024, 2, 9, 23)
, other arguments unchanged.
When the start date falls on a day within the weekmask in CustomBusinessDay
, date_range
output does not include 2024-02-15 (Thursday). However, when the start date is on a day not included in the weekmask (Friday or Saturday), date_range
does include 2024-02-15.
Expected Behavior
With a freq of CustomBusinessDay(weekmask='Sun Mon Tue Wed Thu')
and an end of 2024-02-16, I'd expect date_range
to always include 2024-02-15, regardless of start.
Installed Versions
INSTALLED VERSIONS
commit : 2e218d1
python : 3.10.4.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.22621
machine : AMD64
processor : Intel64 Family 6 Model 141 Stepping 1, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : English_United States.1252
pandas : 1.5.3
numpy : 1.24.3
pytz : 2022.7.1
dateutil : 2.8.2
setuptools : 58.1.0
pip : 24.0
Cython : 0.29.32
pytest : 7.2.1
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : 3.0.3
lxml.etree : 4.9.1
html5lib : 1.1
pymysql : 1.0.2
psycopg2 : None
jinja2 : 3.1.2
IPython : 8.4.0
pandas_datareader: None
bs4 : 4.11.1
bottleneck : None
brotli : None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : 3.5.3
numba : None
numexpr : None
odfpy : None
openpyxl : 3.1.1
pandas_gbq : None
pyarrow : 15.0.0
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : 1.9.0
snappy : None
sqlalchemy : 2.0.12
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
zstandard : None
tzdata : 2023.3