Skip to content

Commit 14946f8

Browse files
committed
use DTI constructor
1 parent 998920c commit 14946f8

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

pandas/core/dtypes/cast.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -912,19 +912,15 @@ def try_datetime(v):
912912

913913
# we might have a sequence of the same-datetimes with tz's
914914
# if so coerce to a DatetimeIndex; if they are not the same,
915-
# then these stay as object dtype
916-
917-
# GH19671
918-
# replaced to_datetime call with
919-
# tslibs.conversion.datetime_to_datetime64
920-
# in order to avoid changes to public to_datetime API
915+
# then these stay as object dtype, xref GH19671
921916
try:
922917
from pandas._libs.tslibs import conversion
923-
from pandas.core.indexes.datetimes import DatetimeIndex
918+
from pandas import DatetimeIndex
924919

925920
values, tz = conversion.datetime_to_datetime64(v)
926-
return DatetimeIndex._simple_new(values, tz=tz)
927-
except Exception:
921+
return DatetimeIndex(values).tz_localize(
922+
'UTC').tz_convert(tz=tz)
923+
except (ValueError, TypeError):
928924
pass
929925

930926
except Exception:

0 commit comments

Comments
 (0)