Skip to content
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

BUG: Negative freq in date_range produces values out of start and endpoints #56147

Closed
3 tasks done
jrmylow opened this issue Nov 24, 2023 · 2 comments
Closed
3 tasks done
Assignees
Labels
Bug Needs Triage Issue that has not been reviewed by a pandas team member

Comments

@jrmylow
Copy link
Contributor

jrmylow commented Nov 24, 2023

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

@jrmylow jrmylow added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Nov 24, 2023
@jrmylow
Copy link
Contributor Author

jrmylow commented Nov 24, 2023

I think this is common cause with #56134 and I think I have a fix for both in one go

@jrmylow
Copy link
Contributor Author

jrmylow commented Nov 24, 2023

take

@jrmylow jrmylow changed the title BUG: BUG: Negative freq in date_range produces values out of start and endpoints Nov 24, 2023
jrmylow added a commit to jrmylow/pandas that referenced this issue Nov 24, 2023
jrmylow added a commit to jrmylow/pandas that referenced this issue Nov 24, 2023
jrmylow added a commit to jrmylow/pandas that referenced this issue Jan 11, 2024
jrmylow added a commit to jrmylow/pandas that referenced this issue Jan 11, 2024
jrmylow added a commit to jrmylow/pandas that referenced this issue Jan 11, 2024
mroeschke added a commit that referenced this issue Mar 20, 2024
…points (#56832)

* #56147 negative offset and year end interaction

* #56147 tests

* documentation

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* fixing typing/pylint to mirror other branch

* moved note to Datetimelike

* documentation re-merge

* whatsnew update

* updated date_range docstring

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* reformatted docstring

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update doc/source/whatsnew/v3.0.0.rst

Co-authored-by: Matthew Roeschke <[email protected]>

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Matthew Roeschke <[email protected]>
pmhatre1 pushed a commit to pmhatre1/pandas-pmhatre1 that referenced this issue May 7, 2024
…points (pandas-dev#56832)

* pandas-dev#56147 negative offset and year end interaction

* pandas-dev#56147 tests

* documentation

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* fixing typing/pylint to mirror other branch

* moved note to Datetimelike

* documentation re-merge

* whatsnew update

* updated date_range docstring

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* reformatted docstring

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update doc/source/whatsnew/v3.0.0.rst

Co-authored-by: Matthew Roeschke <[email protected]>

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Matthew Roeschke <[email protected]>
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

Successfully merging a pull request may close this issue.

2 participants