BUG: Negative freq in date_range produces values out of start and endpoints · Issue #56147 · pandas-dev/pandas (original) (raw)
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
start = pd.to_datetime('2023-10-31 00:00:00') end = pd.to_datetime('2021-11-01 00:00:00')
rng = pd.date_range(start=start,end=end,freq='-1Y') print(rng)
DatetimeIndex(['2023-12-31', '2022-12-31', '2021-12-31'], dtype='datetime64[ns]', freq='-1Y-DEC')
Issue Description
When using negative freq
value for the year, the date range produces a value outside the range of start and end points.
Expected Behavior
Expected the resulting dates to fall between start and end>>> DatetimeIndex(['2022-12-31', '2021-12-31'], dtype='datetime64[ns]', freq='-1Y-DEC')
Installed Versions
INSTALLED VERSIONS ------------------
commit : 984d755
python : 3.10.4.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.19045
machine : AMD64
processor : Intel64 Family 6 Model 140 Stepping 2, GenuineIntel
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : English_Australia.1252
pandas : 2.2.0.dev0+471.g984d75543f
numpy : 1.26.1
pytz : 2023.3.post1
dateutil : 2.8.2
setuptools : 58.1.0
pip : 23.3.1
Cython : 0.29.33
pytest : 7.4.3
hypothesis : 6.88.1
sphinx : 6.2.1
blosc : 1.11.1
feather : None
xlsxwriter : 3.1.9
lxml.etree : 4.9.3
html5lib : 1.1
pymysql : 1.4.6
psycopg2 : 2.9.9
jinja2 : 3.1.2
IPython : 8.16.1
pandas_datareader : None
bs4 : 4.12.2
bottleneck : 1.3.7
dataframe-api-compat: None
fastparquet : 2023.10.1
fsspec : 2023.10.0
gcsfs : 2023.10.0
matplotlib : 3.7.3
numba : 0.58.1
numexpr : 2.8.7
odfpy : None
openpyxl : 3.1.2
pandas_gbq : None
pyarrow : 13.0.0
pyreadstat : 1.2.4
python-calamine : None
pyxlsb : 1.0.10
s3fs : 2023.10.0
scipy : 1.11.3
sqlalchemy : 2.0.22
tables : 3.9.1
tabulate : 0.9.0
xarray : 2023.10.1
xlrd : 2.0.1
zstandard : 0.21.0
tzdata : 2023.3
qtpy : None
pyqt5 : None