Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v0.21.1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ Conversion
- Bug in :class:`DatetimeIndex` subtracting datetimelike from DatetimeIndex could fail to overflow (:issue:`18020`)
- Bug in :meth:`IntervalIndex.copy` when copying and ``IntervalIndex`` with non-default ``closed`` (:issue:`18339`)
- Bug in :func:`DataFrame.to_dict` where columns of datetime that are tz-aware were not converted to required arrays when used with ``orient='records'``, raising``TypeError` (:issue:`18372`)
-
- Bug in :class:`DateTimeIndex` and :meth:`date_range` where mismatching tz-aware ``start`` and ``end`` timezones would not raise an err if ``end.tzinfo`` is None (:issue:`18431`)
-

Indexing
Expand Down
7 changes: 3 additions & 4 deletions pandas/_libs/tslibs/timezones.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -284,10 +284,9 @@ cdef object get_dst_info(object tz):
def infer_tzinfo(start, end):
if start is not None and end is not None:
tz = start.tzinfo
if end.tzinfo:
if not (get_timezone(tz) == get_timezone(end.tzinfo)):
msg = 'Inputs must both have the same timezone, {tz1} != {tz2}'
raise AssertionError(msg.format(tz1=tz, tz2=end.tzinfo))
if not (get_timezone(tz) == get_timezone(end.tzinfo)):
msg = 'Inputs must both have the same timezone, {tz1} != {tz2}'
raise AssertionError(msg.format(tz1=tz, tz2=end.tzinfo))
elif start is not None:
tz = start.tzinfo
elif end is not None:
Expand Down
16 changes: 16 additions & 0 deletions pandas/tests/indexes/datetimes/test_date_range.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,22 @@ def test_precision_finer_than_offset(self):
tm.assert_index_equal(result1, expected1)
tm.assert_index_equal(result2, expected2)

dt1, dt2 = '2017-01-01', '2017-01-01'
tz1, tz2 = 'US/Eastern', 'Europe/London'

@pytest.mark.parametrize("start,end", [
(pd.Timestamp(dt1, tz=tz1), pd.Timestamp(dt2)),
(pd.Timestamp(dt1), pd.Timestamp(dt2, tz=tz2)),
(pd.Timestamp(dt1, tz=tz1), pd.Timestamp(dt2, tz=tz2)),
(pd.Timestamp(dt1, tz=tz2), pd.Timestamp(dt2, tz=tz1))
])
def test_mismatching_tz_raises_err(self, start, end):
# issue 18488
with pytest.raises(TypeError):
pd.date_range(start, end)
with pytest.raises(TypeError):
pd.DatetimeIndex(start, end, freq=BDay())


class TestBusinessDateRange(object):

Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/tseries/test_timezones.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ def test_with_tz(self):

# datetimes with tzinfo set
dr = bdate_range(datetime(2005, 1, 1, tzinfo=pytz.utc),
'1/1/2009', tz=pytz.utc)
datetime(2009, 1, 1, tzinfo=pytz.utc))

pytest.raises(Exception, bdate_range,
datetime(2005, 1, 1, tzinfo=pytz.utc), '1/1/2009',
Expand Down