You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The behaviour of date_range is inconsistent when using the argument inclusive="right".
When the time delta between the start and end point of a date_range with inclusive="right" is shorter than the freq argument then an empty DatetimeIndex is returned. However, when the start and end points are the same (i.e. the time delta is zero), then a DatetimeIndex including the 'rightmost' argument is returned (which is, obviously, also the start time). This appears to be inconsistent: if an empty DatetimeIndex is returned when the time delta between the arguments is shorter than the specified frequency, then it should also return an empty DatetimeIndex when the time delta is zero (or, equally, it should return the end time in both cases).
Expected Behavior
For consistency in the above example, either
print(pd.date_range("2025-01-01 00:05:00", "2025-01-01 00:10:00", freq="10min", inclusive="right")) # 5min gap
should return DatetimeIndex(['2025-01-01 00:10:00'], dtype='datetime64[ns]', freq='10min'), or
print(pd.date_range("2025-01-01 00:10:00", "2025-01-01 00:10:00", freq="10min", inclusive="right")) # 0min gap
should return DatetimeIndex([], dtype='datetime64[ns]', freq='10min').
Installed Versions
INSTALLED VERSIONS
commit : e2bd8e6
python : 3.13.2
python-bits : 64
OS : Linux
OS-release : 5.14.0-162.6.1.el9_1.x86_64
Version : #1 SMP PREEMPT_DYNAMIC Fri Nov 18 02:06:38 UTC 2022
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_GB.UTF-8
LOCALE : en_GB.UTF-8
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
Issue Description
The behaviour of
date_range
is inconsistent when using the argumentinclusive="right"
.When the time delta between the start and end point of a
date_range
withinclusive="right"
is shorter than thefreq
argument then an emptyDatetimeIndex
is returned. However, when the start and end points are the same (i.e. the time delta is zero), then aDatetimeIndex
including the 'rightmost' argument is returned (which is, obviously, also the start time). This appears to be inconsistent: if an emptyDatetimeIndex
is returned when the time delta between the arguments is shorter than the specified frequency, then it should also return an emptyDatetimeIndex
when the time delta is zero (or, equally, it should return the end time in both cases).Expected Behavior
For consistency in the above example, either
should return
DatetimeIndex(['2025-01-01 00:10:00'], dtype='datetime64[ns]', freq='10min')
, orshould return
DatetimeIndex([], dtype='datetime64[ns]', freq='10min')
.Installed Versions
INSTALLED VERSIONS
commit : e2bd8e6
python : 3.13.2
python-bits : 64
OS : Linux
OS-release : 5.14.0-162.6.1.el9_1.x86_64
Version : #1 SMP PREEMPT_DYNAMIC Fri Nov 18 02:06:38 UTC 2022
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_GB.UTF-8
LOCALE : en_GB.UTF-8
pandas : 3.0.0.dev0+2123.ge2bd8e60f0
numpy : 2.3.0.dev0+git20250520.2a7a0d0
dateutil : 2.9.0.post0
pip : 25.1
Cython : None
sphinx : None
IPython : None
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : None
bottleneck : None
fastparquet : None
fsspec : None
html5lib : None
hypothesis : None
gcsfs : None
jinja2 : None
lxml.etree : None
matplotlib : None
numba : None
numexpr : None
odfpy : None
openpyxl : None
psycopg2 : None
pymysql : None
pyarrow : None
pyiceberg : None
pyreadstat : None
pytest : None
python-calamine : None
pytz : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlsxwriter : None
zstandard : None
tzdata : 2025.2
qtpy : None
pyqt5 : None
The text was updated successfully, but these errors were encountered: