Closed
Description
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
pd.to_datetime("2017-09-18") - pd.offsets.YearBegin()
#> Timestamp('2017-01-01 00:00:00') - My expectation was correct as I expected exactly the output of the function
pd.to_datetime("2018-01-01") - pd.offsets.YearBegin()
#> Timestamp('2017-01-01 00:00:00') - My expectation was wrong as I expected Timestamp('2018-01-01 00:00:00')
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:
pd.to_datetime("2017-09-18") - pd.offsets.YearBegin()
#> Timestamp('2017-01-01 00:00:00') - My expectation was correct as I expected exactly the output of the function
pd.to_datetime("2018-01-01") - pd.offsets.YearBegin()
#> Timestamp('2017-01-01 00:00:00') - My expectation was wrong as I expected Timestamp('2018-01-01 00:00:00')
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
pd.to_datetime("2018-01-01") - pd.offsets.YearBegin()
#> Timestamp('2018-01-01 00:00:00')
Installed Versions
pandas 1.4.4
Python 3.9.16