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 b5e53e9 commit d887566Copy full SHA for d887566
pandas/core/dtypes/cast.py
@@ -170,7 +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
- result = result.astype(dtype)
+ 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)
183
184
return result
185
0 commit comments