Skip to content

Commit 9ada28a

Browse files
committed
BUG: DateRange union bug caused by DateOffset __ne__ not being implemented, GH #456
1 parent def3886 commit 9ada28a

File tree

4 files changed

+30
-0
lines changed

4 files changed

+30
-0
lines changed

RELEASE.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ pandas 0.6.1
5757
- Don't "accidentally" upcast scalar values when indexing using .ix (GH #431)
5858
- Fix groupby exception raised with as_index=False and single column selected
5959
(GH #421)
60+
- Implement DateOffset.__ne__ causing downstream bug (GH #456)
6061

6162
Thanks
6263
------

pandas/core/datetools.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,9 @@ def __repr__(self):
159159
def __eq__(self, other):
160160
return self._params() == other._params()
161161

162+
def __ne__(self, other):
163+
return not self == other
164+
162165
def __hash__(self):
163166
return hash(self._params())
164167

pandas/tests/test_daterange.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,15 @@ def test_date_parse_failure(self):
306306
def test_equals(self):
307307
self.assertFalse(self.rng.equals(list(self.rng)))
308308

309+
def test_daterange_bug_456(self):
310+
# GH #456
311+
rng1 = DateRange('12/5/2011', '12/5/2011')
312+
rng2 = DateRange('12/2/2011', '12/5/2011')
313+
rng2.offset = datetools.BDay()
314+
315+
result = rng1.union(rng2)
316+
self.assert_(type(result) == DateRange)
317+
309318
def _skip_if_no_pytz():
310319
try:
311320
import pytz

pandas/tests/test_datetools.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,12 @@ def test_apply(self):
192192
def test_apply_corner(self):
193193
self.assertRaises(Exception, BDay().apply, BMonthEnd())
194194

195+
def test_offsets_compare_equal(self):
196+
# root cause of #456
197+
offset1 = BDay()
198+
offset2 = BDay()
199+
self.assertFalse(offset1 != offset2)
200+
195201
def assertOnOffset(offset, date, expected):
196202
actual = offset.onOffset(date)
197203
assert actual == expected
@@ -253,6 +259,11 @@ def test_onOffset(self):
253259
expected = False
254260
assertOnOffset(offset, date, expected)
255261

262+
def test_offsets_compare_equal(self):
263+
# root cause of #456
264+
offset1 = Week()
265+
offset2 = Week()
266+
self.assertFalse(offset1 != offset2)
256267

257268
class TestWeekOfMonth(unittest.TestCase):
258269

@@ -377,6 +388,12 @@ def test_onOffset(self):
377388
for offset, date, expected in tests:
378389
assertOnOffset(offset, date, expected)
379390

391+
def test_offsets_compare_equal(self):
392+
# root cause of #456
393+
offset1 = BMonthEnd()
394+
offset2 = BMonthEnd()
395+
self.assertFalse(offset1 != offset2)
396+
380397
class TestMonthEnd(unittest.TestCase):
381398

382399
def test_offset(self):

0 commit comments

Comments
 (0)