We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 7b6cf39 commit 51557f4Copy full SHA for 51557f4
pandas/core/dtypes/cast.py
@@ -170,16 +170,16 @@ def maybe_downcast_to_dtype(result, dtype):
170
# a datetimelike
171
# GH12821, iNaT is cast to float
172
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:
+ if hasattr(dtype, "tz"):
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)
+ else:
+ result = result.astype(dtype)
183
184
return result
185
0 commit comments