t = pd.Timestamp('2020-02-05')
print(pd.offsets.QuarterBegin().rollback(t))
print(pd.offsets.QuarterEnd().rollback(t))
out:
2019-12-01 00:00:00
2019-12-31 00:00:00
why the result is 2019-12-01? Shouldn't it be 2020-01-01?
t = pd.Timestamp('2020-02-05')
print(pd.offsets.QuarterBegin().rollback(t))
print(pd.offsets.QuarterEnd().rollback(t))
out:
2019-12-01 00:00:00
2019-12-31 00:00:00
why the result is 2019-12-01? Shouldn't it be 2020-01-01?
The docs specify that there is a startingMonth; e.g. "startingMonth = 3 corresponds to dates like 3/01/2007, 6/01/2007". To find out what the default of this keyword argument is, you can have a look at the src and observe that _default_starting_month = 3 (link).
So without providing startingMonth, your quarters start at month = 3, 6, 9, 12 - which is why you get 2019-12-01 00:00:00 if you "rollback" pd.Timestamp('2020-02-05').
If you want your quarters to start e.g. on month = 1, 4, ... and end on month = 3, 6, ... (inclusive), you can set the keyword to 1 (and 3 respectively for QuarterEnd):
t = pd.Timestamp('2020-02-05')
print(pd.offsets.QuarterBegin(startingMonth=1).rollback(t))
print(pd.offsets.QuarterEnd(startingMonth=3).rollback(t))
2020-01-01 00:00:00
2019-12-31 00:00:00