Skip to content

Quarter.onOffset looks fishy #18235

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

Open
jbrockmendel opened this issue Nov 12, 2017 · 1 comment
Open

Quarter.onOffset looks fishy #18235

jbrockmendel opened this issue Nov 12, 2017 · 1 comment
Labels
Bug Frequency DateOffsets

Comments

@jbrockmendel
Copy link
Member

qe = pd.offsets.QuarterEnd(startingMonth=2)
qs = pd.offsets.QuarterBegin(startingMonth=2)
bqe = pd.offsets.BQuarterEnd(startingMonth=2)
bqs = pd.offsets.BQuarterBegin(startingMonth=2)

feb1 = pd.Timestamp('2017-02-01')
feb28 = pd.Timestamp('2017-02-28')
apr30 = pd.Timestamp('2017-04-30')

>>> qs.onOffset(feb1)
True
>>> qe.onOffset(feb28)
True
>>> qe.onOffset(apr30)
False

>>> bqs.onOffset(feb1)
True
>>> bqe.onOffset(feb28)
True
>>> bqe.onOffset(apr30)
False

The QuarterStart behavior makes sense to me; the QuarterEnd does not. If Feb1 is the start of a quarter, shouldn't the end of that same quarter be Apr30?

@jbrockmendel
Copy link
Member Author

On a closer look, it appears that the behavior is correct but misleading. QuarterEnd(startingMonth=2) is an offset for quarters that start on Feb 1, May 1, Aug 1, Nov 1. I assumed that QuarterEnd(startingMonth=2) would be an offset corresponding to the ends of those same quarters. That is incorrect. QuarterEnd(startingMonth=2) is an offset for quarters that end on Feb 2[89], May 31, Aug 31, Nov 30.

I'm not the first to make this mistake or otherwise end up confused:

I suggest the following:

  • startingMonth should be replaced with something non-camelCase anyway, so let's take the opportunity to replace a problematic kwarg with a clear one.
  • Just brainstorming here: q1start_month=2 means Q1 begins Feb1 and ends Apr 30 (\pm business days)
  • Methods of the form to_qtr_end, to_qtr_business_begin, to_year_end (hopefully its obvious what they would do).

Thoughts? I'm happy to implement+test, but would like to get buy-in first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Frequency DateOffsets
Projects
None yet
Development

No branches or pull requests

2 participants