Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

BUG: Easter works incorrectly in negative offsets #7195

Merged
merged 1 commit into from Jun 3, 2014
Jump to file or symbol
Failed to load files and symbols.
+24 −5
Split
View
@@ -86,3 +86,4 @@ Bug Fixes
wouldn't test ``True`` when it encountered an ``inf``/``-inf``
(:issue:`7315`).
- Bug in inferred_freq results in None for eastern hemisphere timezones (:issue:`7310`)
+- Bug in ``Easter`` returns incorrect date when offset is negative (:issue:`7195`)
View
@@ -1846,12 +1846,16 @@ def apply(self, other):
currentEaster = datetime(currentEaster.year, currentEaster.month, currentEaster.day)
# NOTE: easter returns a datetime.date so we have to convert to type of other
- if other >= currentEaster:
- new = easter(other.year + self.n)
- elif other < currentEaster:
- new = easter(other.year + self.n - 1)
+ if self.n >= 0:
+ if other >= currentEaster:
+ new = easter(other.year + self.n)
+ else:
+ new = easter(other.year + self.n - 1)
else:
- new = other
+ if other > currentEaster:
+ new = easter(other.year + self.n + 1)
+ else:
+ new = easter(other.year + self.n)
# FIXME: There has to be a better way to do this, but I don't know what it is
if isinstance(other, Timestamp):
@@ -2483,16 +2483,30 @@ def test_onOffset(self):
def assertEq(offset, base, expected):
actual = offset + base
actual_swapped = base + offset
+ actual_apply = offset.apply(base)
try:
assert actual == expected
assert actual_swapped == expected
+ assert actual_apply == expected
except AssertionError:
raise AssertionError("\nExpected: %s\nActual: %s\nFor Offset: %s)"
"\nAt Date: %s" %
(expected, actual, offset, base))
def test_Easter():
assertEq(Easter(), datetime(2010, 1, 1), datetime(2010, 4, 4))
+ assertEq(Easter(), datetime(2010, 4, 5), datetime(2011, 4, 24))
+ assertEq(Easter(2), datetime(2010, 1, 1), datetime(2011, 4, 24))
+
+ assertEq(Easter(), datetime(2010, 4, 4), datetime(2011, 4, 24))
+ assertEq(Easter(2), datetime(2010, 4, 4), datetime(2012, 4, 8))
+
+ assertEq(-Easter(), datetime(2011, 1, 1), datetime(2010, 4, 4))
+ assertEq(-Easter(), datetime(2010, 4, 5), datetime(2010, 4, 4))
+ assertEq(-Easter(2), datetime(2011, 1, 1), datetime(2009, 4, 12))
+
+ assertEq(-Easter(), datetime(2010, 4, 4), datetime(2009, 4, 12))
+ assertEq(-Easter(2), datetime(2010, 4, 4), datetime(2008, 3, 23))
def test_Hour():
assertEq(Hour(), datetime(2010, 1, 1), datetime(2010, 1, 1, 1))