Skip to content

Commit fba0724

Browse files
multilocafragner
authored and
afragner
committed
BUG fix GH12409
do comparison for closed intervals on UTC basis prior to tz conversion added tests for date_range covering case of tz-aware start/end dates with closed ranges added issue number to test case update whatsnew added more tests fixed broken unittest
1 parent 49f99a6 commit fba0724

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

doc/source/whatsnew/v0.18.0.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1022,7 +1022,7 @@ Bug Fixes
10221022
- Bug in ``GroupBy.size`` when data-frame is empty. (:issue:`11699`)
10231023
- Bug in ``Period.end_time`` when a multiple of time period is requested (:issue:`11738`)
10241024
- Regression in ``.clip`` with tz-aware datetimes (:issue:`11838`)
1025-
- Bug in ``date_range`` when the boundaries fell on the frequency (:issue:`11804`)
1025+
- Bug in ``date_range`` when the boundaries fell on the frequency (:issue:`11804`, :issue:`12409`)
10261026
- Bug in consistency of passing nested dicts to ``.groupby(...).agg(...)`` (:issue:`9052`)
10271027
- Accept unicode in ``Timedelta`` constructor (:issue:`11995`)
10281028
- Bug in value label reading for ``StataReader`` when reading incrementally (:issue:`12014`)

pandas/tseries/index.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -528,12 +528,12 @@ def _generate(cls, start, end, periods, name, offset,
528528
ambiguous=ambiguous)
529529
index = index.view(_NS_DTYPE)
530530

531-
index = cls._simple_new(index, name=name, freq=offset, tz=tz)
532531
if not left_closed and len(index) and index[0] == start:
533532
index = index[1:]
534533
if not right_closed and len(index) and index[-1] == end:
535534
index = index[:-1]
536535

536+
index = cls._simple_new(index, name=name, freq=offset, tz=tz)
537537
return index
538538

539539
@property

pandas/tseries/tests/test_daterange.py

+30
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,36 @@ def test_range_closed(self):
497497
self.assertTrue(expected_left.equals(left))
498498
self.assertTrue(expected_right.equals(right))
499499

500+
def test_range_closed_with_tz_aware_start_end(self):
501+
# GH12409
502+
begin = Timestamp('2011/1/1', tz='US/Eastern')
503+
end = Timestamp('2014/1/1', tz='US/Eastern')
504+
505+
for freq in ["3D", "2M", "7W", "3H", "A"]:
506+
closed = date_range(begin, end, closed=None, freq=freq)
507+
left = date_range(begin, end, closed="left", freq=freq)
508+
right = date_range(begin, end, closed="right", freq=freq)
509+
expected_left = left
510+
expected_right = right
511+
512+
if end == closed[-1]:
513+
expected_left = closed[:-1]
514+
if begin == closed[0]:
515+
expected_right = closed[1:]
516+
517+
self.assertTrue(expected_left.equals(left))
518+
self.assertTrue(expected_right.equals(right))
519+
520+
# test with default frequency, UTC
521+
begin = Timestamp('2011/1/1', tz='UTC')
522+
end = Timestamp('2014/1/1', tz='UTC')
523+
524+
intervals = ['left', 'right', None]
525+
for i in intervals:
526+
result = date_range(start=begin, end=end, closed=i)
527+
self.assertEqual(result[0], begin)
528+
self.assertEqual(result[-1], end)
529+
500530
def test_range_closed_boundary(self):
501531
# GH 11804
502532
for closed in ['right', 'left', None]:

0 commit comments

Comments
 (0)