Skip to content

Commit 7b6cf39

Browse files
committed
revert datelike if-else body
1 parent 651ac7d commit 7b6cf39

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

pandas/core/dtypes/cast.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,16 @@ def maybe_downcast_to_dtype(result, dtype):
170170
# a datetimelike
171171
# GH12821, iNaT is cast to float
172172
if dtype.kind in ["M", "m"] and result.dtype.kind in ["i", "f"]:
173-
result = result.astype(dtype)
173+
if is_datetime_or_timedelta_dtype(dtype):
174+
result = result.astype(dtype)
175+
else:
176+
# not a numpy dtype
177+
if dtype.tz:
178+
# convert to datetime and change timezone
179+
from pandas import to_datetime
180+
181+
result = to_datetime(result).tz_localize("utc")
182+
result = result.tz_convert(dtype.tz)
174183

175184
return result
176185

0 commit comments

Comments
 (0)