Skip to content

BUG: date_range behaviour is inconsistent when using inclusive=right #61483

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
3 tasks done
sebastian-east opened this issue May 23, 2025 · 0 comments
Open
3 tasks done
Labels
Bug Needs Triage Issue that has not been reviewed by a pandas team member

Comments

@sebastian-east
Copy link

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

# demonstration of (default) behaviour with inclusive = both
print(pd.date_range("2025-01-01 00:00:00", "2025-01-01 00:10:00", freq="10min", inclusive="both")) # 10min gap
print(pd.date_range("2025-01-01 00:05:00", "2025-01-01 00:10:00", freq="10min", inclusive="both")) # 5min gap
print(pd.date_range("2025-01-01 00:10:00", "2025-01-01 00:10:00", freq="10min", inclusive="both")) # 0min gap

# demonstration of behaviour with inclusive = right
print(pd.date_range("2025-01-01 00:00:00", "2025-01-01 00:10:00", freq="10min", inclusive="right")) # 10min gap
print(pd.date_range("2025-01-01 00:05:00", "2025-01-01 00:10:00", freq="10min", inclusive="right")) # 5min gap
print(pd.date_range("2025-01-01 00:10:00", "2025-01-01 00:10:00", freq="10min", inclusive="right")) # 0min gap

Issue Description

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 : 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

@sebastian-east sebastian-east added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels May 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Needs Triage Issue that has not been reviewed by a pandas team member
Projects
None yet
Development

No branches or pull requests

1 participant