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: fix to_datetime(dti, utc=True) #27733

Merged
merged 5 commits into from Aug 5, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions pandas/core/tools/datetimes.py
Expand Up @@ -334,6 +334,9 @@ def _convert_listlike_datetimes(
return DatetimeIndex(arg, tz=tz, name=name)
except ValueError:
pass
elif box and tz:
jbrockmendel marked this conversation as resolved.
Show resolved Hide resolved
# DatetimeArray, DatetimeIndex
return arg.tz_localize(tz)

return arg

Expand Down
10 changes: 10 additions & 0 deletions pandas/tests/indexes/datetimes/test_tools.py
Expand Up @@ -1623,6 +1623,16 @@ def test_dayfirst(self, cache):
tm.assert_index_equal(expected, idx5)
tm.assert_index_equal(expected, idx6)

def test_to_datetime_dta_tz(self):
dti = date_range("2015-04-05", periods=3).rename("foo")
jreback marked this conversation as resolved.
Show resolved Hide resolved
expected = dti.tz_localize("UTC")
result = to_datetime(dti, utc=True)
tm.assert_index_equal(result, expected)

jreback marked this conversation as resolved.
Show resolved Hide resolved
dta = dti._data
jbrockmendel marked this conversation as resolved.
Show resolved Hide resolved
result = to_datetime(dta, utc=True)
tm.assert_equal(result, expected._data)


class TestGuessDatetimeFormat:
@td.skip_if_not_us_locale
Expand Down