Skip to content

Commit 51557f4

Browse files
committed
feedback: revert datetimelike block
1 parent 7b6cf39 commit 51557f4

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

pandas/core/dtypes/cast.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -170,16 +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-
if is_datetime_or_timedelta_dtype(dtype):
174-
result = result.astype(dtype)
175-
else:
173+
if hasattr(dtype, "tz"):
176174
# not a numpy dtype
177175
if dtype.tz:
178176
# convert to datetime and change timezone
179177
from pandas import to_datetime
180178

181179
result = to_datetime(result).tz_localize("utc")
182180
result = result.tz_convert(dtype.tz)
181+
else:
182+
result = result.astype(dtype)
183183

184184
return result
185185

0 commit comments

Comments
 (0)