-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: Is offsets.YearBegin working as expected? #52105
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
Comments
Thanks for the report, I'd have expected
In [74]: to_datetime(["2017-09-18", "2018-01-01"]) + pd.offsets.YearBegin() - pd.offsets.YearBegin()
Out[74]: DatetimeIndex(['2017-01-01', '2018-01-01'], dtype='datetime64[ns]', freq=None)
Not sure, I'll take a look this week ps. Ciao Mirko! |
instead of addition/subtraction you want rollforward/rollback |
sure, but that can't be vectorised, can it? I can do to_datetime(["2017-09-18", "2018-01-01"]) + pd.offsets.YearBegin() but pd.offsets.YearBegin().rollbackward(to_datetime(["2017-09-18", "2018-01-01"])) doesn't work, I'd need to do it element-by-element |
Yah we do need rollfoward/rollbackward for arrays, xref #7449. Also it would help for some of the recent issues with users trying to do |
Right, the docs for DateOffset say
So, we probably shouldn't recommend it in the docs. From #7449, it seems the simplest solution is
I think it'd be really good to include this example in the |
Re - the docs, it might be good to mirror the |
Hi @mirkosavasta, do you want to do the PR for this issue? If you don't want to, I'll add examples to |
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
Hello,
The documentation for
offsets.YearBegin
states "DateOffset increments between calendar year begin dates."I do not understand if my expectations about the behaviour of
offsets.YearBegin
are correct or not. Please see the code below:Why if I subtract
offsets.YearBegin()
from the first day of the year I get the first day of the previous year? Is this expected?If so, I could improve the documentation. If not, I guess this could be a bug.
Thanks in advance.
Expected Behavior
Installed Versions
pandas 1.4.4
Python 3.9.16
The text was updated successfully, but these errors were encountered: