Skip to content

Commit

Permalink
BUG: to_datetime(strs, utc=True) used previous UTC offset (pandas-dev…
Browse files Browse the repository at this point in the history
  • Loading branch information
mroeschke authored and Pingviinituutti committed Feb 28, 2019
1 parent 651d366 commit 9147d5f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v0.25.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ Timedelta
Timezones
^^^^^^^^^

-
- Bug in :func:`to_datetime` with ``utc=True`` and datetime strings that would apply previously parsed UTC offsets to subsequent arguments (:issue:`24992`)
-
-

Expand Down
2 changes: 2 additions & 0 deletions pandas/_libs/tslib.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,8 @@ cpdef array_to_datetime(ndarray[object] values, str errors='raise',
out_tzoffset_vals.add(out_tzoffset * 60.)
tz = pytz.FixedOffset(out_tzoffset)
value = tz_convert_single(value, tz, UTC)
out_local = 0
out_tzoffset = 0
else:
# Add a marker for naive string, to track if we are
# parsing mixed naive and aware strings
Expand Down
23 changes: 23 additions & 0 deletions pandas/tests/indexes/datetimes/test_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,29 @@ def test_iso_8601_strings_with_different_offsets(self):
NaT], tz='UTC')
tm.assert_index_equal(result, expected)

def test_iss8601_strings_mixed_offsets_with_naive(self):
# GH 24992
result = pd.to_datetime([
'2018-11-28T00:00:00',
'2018-11-28T00:00:00+12:00',
'2018-11-28T00:00:00',
'2018-11-28T00:00:00+06:00',
'2018-11-28T00:00:00'
], utc=True)
expected = pd.to_datetime([
'2018-11-28T00:00:00',
'2018-11-27T12:00:00',
'2018-11-28T00:00:00',
'2018-11-27T18:00:00',
'2018-11-28T00:00:00'
], utc=True)
tm.assert_index_equal(result, expected)

items = ['2018-11-28T00:00:00+12:00', '2018-11-28T00:00:00']
result = pd.to_datetime(items, utc=True)
expected = pd.to_datetime(list(reversed(items)), utc=True)[::-1]
tm.assert_index_equal(result, expected)

def test_non_iso_strings_with_tz_offset(self):
result = to_datetime(['March 1, 2018 12:00:00+0400'] * 2)
expected = DatetimeIndex([datetime(2018, 3, 1, 12,
Expand Down

0 comments on commit 9147d5f

Please sign in to comment.