Skip to content
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

BUG/API: QuarterBegin n=0 #11406 #11777

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 28 additions & 0 deletions doc/source/whatsnew/v0.18.0.txt
Expand Up @@ -89,12 +89,40 @@ In addition, ``.round()`` will be available thru the ``.dt`` accessor of ``Serie
Backwards incompatible API changes
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Bug in QuarterBegin with n=0
^^^^^^^^^^^^^^^^^^^^^^^^^^^^

In previous versions, the behavior of the QuarterBegin offset was inconsistent
depending on the date when the ``n`` parameter was 0.

The general semantics of anchored offsets for ``n=0`` is to not move the date
when it is an anchor point (e.g., a quarter start date), and otherwise roll
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add the issue number reference here

forward to the next anchor point.

.. ipython:: python

d = pd.Timestamp('2014-02-01')
d
d + pd.offsets.QuarterBegin(n=0, startingMonth=2)
d + pd.offsets.QuarterBegin(n=0, startingMonth=1)

For the ``QuarterBegin`` offset in previous versions, the date would be rolled
*backwards* if date was in the same month as the quarter start date.

.. code-block:: python

In [3]: d = pd.Timestamp('2014-02-15')

In [4]: d + pd.offsets.QuarterBegin(n=0, startingMonth=2)
Out[4]: Timestamp('2014-02-01 00:00:00')

This behavior has been corrected in version 0.18.0, which is consistent with
other anchored offsets like ``MonthBegin`` and ``YearBegin``.

.. ipython:: python

d = pd.Timestamp('2014-02-15')
d + pd.offsets.QuarterBegin(n=0, startingMonth=2)


Other API Changes
Expand Down
2 changes: 1 addition & 1 deletion pandas/tseries/offsets.py
Expand Up @@ -1767,7 +1767,7 @@ def apply(self, other):
# make sure you roll forward, so negate
monthsSince = monthsSince - 3

if n < 0 and (monthsSince == 0 and other.day > 1):
if n <= 0 and (monthsSince == 0 and other.day > 1):
# after start, so come back an extra period as if rolled forward
n = n + 1

Expand Down
4 changes: 2 additions & 2 deletions pandas/tseries/tests/test_offsets.py
Expand Up @@ -2918,8 +2918,8 @@ def test_offset(self):
datetime(2008, 2, 29): datetime(2008, 4, 1),
datetime(2008, 3, 15): datetime(2008, 4, 1),
datetime(2008, 3, 31): datetime(2008, 4, 1),
datetime(2008, 4, 15): datetime(2008, 4, 1),
datetime(2008, 4, 30): datetime(2008, 4, 1), }))
datetime(2008, 4, 15): datetime(2008, 7, 1),
datetime(2008, 4, 30): datetime(2008, 7, 1), }))

tests.append((QuarterBegin(startingMonth=1, n=-1),
{datetime(2008, 1, 1): datetime(2007, 10, 1),
Expand Down