Skip to content

BUG: Some date-like Offset.apply resets time #7156

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

Closed
sinhrks opened this issue May 17, 2014 · 3 comments · Fixed by #7375
Closed

BUG: Some date-like Offset.apply resets time #7156

sinhrks opened this issue May 17, 2014 · 3 comments · Fixed by #7375
Labels
Bug Frequency DateOffsets Testing pandas testing functions or related to the test suite
Milestone

Comments

@sinhrks
Copy link
Member

sinhrks commented May 17, 2014

There seems to be inconsistencies regarding time (hours, minutes, etc) handling of Offset.apply. Maybe all these should preserve hours/minutes like DayOffset? Or any other rules?

Followings are results offset(n=1) applied to datetime(2011, 1, 1, 9, 0).

# Offsets which preserves time
(<Day>, datetime.datetime(2011, 1, 2, 9, 0))
(<BusinessDay>, Timestamp('2011-01-03 09:00:00'))
(<CustomBusinessDay>, Timestamp('2011-01-03 09:00:00'))
(<MonthBegin>, Timestamp('2011-02-01 09:00:00'))
(<CustomBusinessMonthBegin>, Timestamp('2011-01-03 09:00:00'))
(<YearBegin: month=1>, Timestamp('2012-01-01 09:00:00'))
(<YearEnd: month=12>, Timestamp('2011-12-31 09:00:00'))
(<BusinessYearEnd: month=12>, Timestamp('2011-12-30 09:00:00'))
(<QuarterBegin: startingMonth=3>, Timestamp('2011-03-01 09:00:00'))
(<BusinessQuarterBegin: startingMonth=3>, Timestamp('2011-03-01 09:00:00'))
(<QuarterEnd: startingMonth=3>, Timestamp('2011-03-31 09:00:00'))
(<BusinessQuarterEnd: startingMonth=3>, Timestamp('2011-03-31 09:00:00'))
(<Week: weekday=None>, Timestamp('2011-01-08 09:00:00'))

# Offsets which don't preserves time
(<BusinessMonthBegin>, Timestamp('2011-01-03 00:00:00'))
(<MonthEnd>, Timestamp('2011-01-31 00:00:00'))
(<BusinessMonthEnd>, Timestamp('2011-01-31 00:00:00'))
(<CustomBusinessMonthEnd>, Timestamp('2011-01-31 00:00:00'))
(<BusinessYearBegin: month=1>, Timestamp('2011-01-03 00:00:00'))
(<LastWeekOfMonth: weekday=5>, Timestamp('2011-01-29 00:00:00'))
(<FY5253Quarter: kwds={'startingMonth': 1, 'weekday': 1, 'variation': 'last'}, qtr_with_extra_week=1>, Timestamp('2011-01-25 00:00:00'))
(<FY5253: kwds={'qtr_with_extra_week': 1}, startingMonth=1, variation='last', weekday=1>, Timestamp('2011-01-25 00:00:00'))
(<LastWeekOfMonth: weekday=5>, Timestamp('2011-01-29 00:00:00'))
(<Easter>, datetime.datetime(2011, 4, 24, 0, 0))
@jreback
Copy link
Contributor

jreback commented May 17, 2014

hmm afaik these should all preserve times

I think the time preservation may not be handled properly in apply

prob no tests for this either

feel free to add tests / fix

@jreback jreback added this to the 0.14.1 milestone May 19, 2014
@sinhrks
Copy link
Member Author

sinhrks commented May 20, 2014

Thanks. I found BusinessDay, CustomBusinessDay, CustomBusinessMonthEnd and CustomBusinessMonthBegin already have normalize option to normalize the date. How about adding normalize option to all the offset with default False?

The option should affect to apply, rollforward, rollback and onOffset.

import pandas as pd
pd.offsets.Day().apply(pd.Timestamp('2011-01-01 09:00:00'))
# 2011-01-02 09:00:00

pd.offsets.Day(normalize=True).apply(pd.Timestamp('2011-01-01 09:00:00'))
# 2011-01-02 00:00:00

pd.offsets.Day().rollforward(pd.Timestamp('2011-01-01 09:00:00'))
# 2011-01-01 09:00:00

pd.offsets.Day(normalize=True).rollforward(pd.Timestamp('2011-01-01 09:00:00'))
# 2011-01-02 00:00:00

pd.offsets.Day().onOffset(pd.Timestamp('2011-01-01 09:00:00'))
# True

pd.offsets.Day(normalize=True).rollforward(pd.Timestamp('2011-01-01 09:00:00'))
# False

pd.offsets.Day(normalize=True).rollforward(pd.Timestamp('2011-01-02 00:00:00'))
# True

@jreback
Copy link
Contributor

jreback commented May 20, 2014

yes I think all offsets should handle normalize (default of False)
refactor out to a function

and tests for all offsets (which is the best way to ensure that they have consistent functionality)
eg out automated tests for all offsets in Base (which we have for other things, eg making sure apply returns a Timestamp for example)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Frequency DateOffsets Testing pandas testing functions or related to the test suite
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants