Clarification on DateOffset and QuarterBegin, QuarterEnd

200 views
Skip to first unread message

lexual

unread,
Feb 25, 2013, 12:36:12 AM2/25/13
to pyd...@googlegroups.com
Hi,

I thought that the following would give me the quarter start and end date for a particular date.

start = mydate - pd.datetools.QuarterBegin()
end = mydate - pd.datetools.QuarterEnd()

But I'm not getting the results I was expecting. Can anyone inform me if I've misunderstood DateOffset, or if this is a bug?

Attached is the result of a test case that can clarify my issue.

As you can see:

 datetime.datetime(2013, 12, 13) - pd.datetools.QuarterBegin()

gives me december 1, when I'm expecting October 1.

This is with Pandas 0.10.1.

With the testcase you can see that the Month* functions behave as I expected, but not the Quarter ones.

Thanks,

Lex.
dateoffset_test.py
offsets.csv

Skipper Seabold

unread,
Feb 25, 2013, 8:26:32 AM2/25/13
to pyd...@googlegroups.com
On Mon, Feb 25, 2013 at 12:36 AM, lexual <lex....@gmail.com> wrote:
> Hi,
>
> I thought that the following would give me the quarter start and end date
> for a particular date.
>
> start = mydate - pd.datetools.QuarterBegin()
> end = mydate - pd.datetools.QuarterEnd()
>
> But I'm not getting the results I was expecting. Can anyone inform me if
> I've misunderstood DateOffset, or if this is a bug?
>
> Attached is the result of a test case that can clarify my issue.
>
> As you can see:
>
> datetime.datetime(2013, 12, 13) - pd.datetools.QuarterBegin()
>
> gives me december 1, when I'm expecting October 1.

First, the default startingMonth for QuarterBegin is 3, which I think
may be leading to your confusion in expecting 10-1. Second, the logic
is that if you're already past a date on the offset, then first roll
forward, then apply the rule. So in your example, you have

12-13-2013, which gets rolled forward onto the offset at 3-1-2014,
then the gets subtracts one quarter to give 12-1-2013.

You want (it doesn't have to be 10, just whenever your year starts
such that October is an offset)

datetime.datetime(2013, 12, 13) - pd.datetools.QuarterBegin(startingMonth=10)


>
> This is with Pandas 0.10.1.
>
> With the testcase you can see that the Month* functions behave as I
> expected, but not the Quarter ones.

The month ones should behave in the same way. 12-13-2013 -> 1-1-2014
-> 12-1-2013.

Skipper

Lex H

unread,
Feb 25, 2013, 5:30:41 PM2/25/13
to pyd...@googlegroups.com
D'oh! I was calling QuarterBegin with startMonth=1 as the argument, not startingMonth=1. Thanks for your help Skipper.

Does anyone else think that default for QuarterBegin's startingMonth should be 1, to bring it into line with QuarterEnd's default of 3.

i.e. calling both QuarterBegin, and QuarterEnd without specifing startingMonth should give the start and end of the same quarter.

expected behaviour:
>>> datetime.date(2013, 12, 13) - pd.datetools.QuarterBegin()
datetime.date(2013, 10, 1)
>>> datetime.date(2013, 12, 13) + pd.datetools.QuarterEnd()
datetime.date(2013, 12, 31)


current behaviour:
>>> datetime.date(2013, 12, 13) - pd.datetools.QuarterBegin()
datetime.date(2013, 12, 1)
>>> datetime.date(2013, 12, 13) + pd.datetools.QuarterEnd()
datetime.date(2013, 12, 31)

I'm happy to create a patch to change QuarterBegin's startingMonth from 3 to 1.

Additionally, it's a bit counter-intuitive to have startingMonth as argument to QuarterEnd. Wouldn't endingMonth be a better choice?

Thanks again,

Lex.



--
You received this message because you are subscribed to the Google Groups "PyData" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pydata+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



Skipper Seabold

unread,
Feb 26, 2013, 9:00:39 AM2/26/13
to pyd...@googlegroups.com
On Mon, Feb 25, 2013 at 5:30 PM, Lex H <lex....@gmail.com> wrote:
> D'oh! I was calling QuarterBegin with startMonth=1 as the argument, not
> startingMonth=1. Thanks for your help Skipper.
>
> Does anyone else think that default for QuarterBegin's startingMonth should
> be 1, to bring it into line with QuarterEnd's default of 3.
>
> i.e. calling both QuarterBegin, and QuarterEnd without specifing
> startingMonth should give the start and end of the same quarter.
>
> expected behaviour:
>>>> datetime.date(2013, 12, 13) - pd.datetools.QuarterBegin()
> datetime.date(2013, 10, 1)
>>>> datetime.date(2013, 12, 13) + pd.datetools.QuarterEnd()
> datetime.date(2013, 12, 31)
>
>
> current behaviour:
>>>> datetime.date(2013, 12, 13) - pd.datetools.QuarterBegin()
> datetime.date(2013, 12, 1)
>>>> datetime.date(2013, 12, 13) + pd.datetools.QuarterEnd()
> datetime.date(2013, 12, 31)
>
> I'm happy to create a patch to change QuarterBegin's startingMonth from 3 to
> 1.
>
> Additionally, it's a bit counter-intuitive to have startingMonth as argument
> to QuarterEnd. Wouldn't endingMonth be a better choice?

I don't like the camel case argument names at all. I'm sure a PR for
changing these to something sensible would be welcome, though you'd
have to deprecate the old argument names.

Skipper
Reply all
Reply to author
Forward
0 new messages