Skip to content

Commit

Permalink
BUG: DateRange union bug caused by DateOffset __ne__ not being implem…
Browse files Browse the repository at this point in the history
…ented, GH #456
  • Loading branch information
wesm committed Dec 8, 2011
1 parent def3886 commit 9ada28a
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions RELEASE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ pandas 0.6.1
- Don't "accidentally" upcast scalar values when indexing using .ix (GH #431)
- Fix groupby exception raised with as_index=False and single column selected
(GH #421)
- Implement DateOffset.__ne__ causing downstream bug (GH #456)

Thanks
------
Expand Down
3 changes: 3 additions & 0 deletions pandas/core/datetools.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,9 @@ def __repr__(self):
def __eq__(self, other):
return self._params() == other._params()

def __ne__(self, other):
return not self == other

def __hash__(self):
return hash(self._params())

Expand Down
9 changes: 9 additions & 0 deletions pandas/tests/test_daterange.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,15 @@ def test_date_parse_failure(self):
def test_equals(self):
self.assertFalse(self.rng.equals(list(self.rng)))

def test_daterange_bug_456(self):
# GH #456
rng1 = DateRange('12/5/2011', '12/5/2011')
rng2 = DateRange('12/2/2011', '12/5/2011')
rng2.offset = datetools.BDay()

result = rng1.union(rng2)
self.assert_(type(result) == DateRange)

def _skip_if_no_pytz():
try:
import pytz
Expand Down
17 changes: 17 additions & 0 deletions pandas/tests/test_datetools.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,12 @@ def test_apply(self):
def test_apply_corner(self):
self.assertRaises(Exception, BDay().apply, BMonthEnd())

def test_offsets_compare_equal(self):
# root cause of #456
offset1 = BDay()
offset2 = BDay()
self.assertFalse(offset1 != offset2)

def assertOnOffset(offset, date, expected):
actual = offset.onOffset(date)
assert actual == expected
Expand Down Expand Up @@ -253,6 +259,11 @@ def test_onOffset(self):
expected = False
assertOnOffset(offset, date, expected)

def test_offsets_compare_equal(self):
# root cause of #456
offset1 = Week()
offset2 = Week()
self.assertFalse(offset1 != offset2)

class TestWeekOfMonth(unittest.TestCase):

Expand Down Expand Up @@ -377,6 +388,12 @@ def test_onOffset(self):
for offset, date, expected in tests:
assertOnOffset(offset, date, expected)

def test_offsets_compare_equal(self):
# root cause of #456
offset1 = BMonthEnd()
offset2 = BMonthEnd()
self.assertFalse(offset1 != offset2)

class TestMonthEnd(unittest.TestCase):

def test_offset(self):
Expand Down

0 comments on commit 9ada28a

Please sign in to comment.