Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: to_datetime(strs, utc=True) used previous UTC offset #25020

Merged
merged 3 commits into from
Jan 31, 2019
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.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