We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent e0ad0c4 commit 4d4066aCopy full SHA for 4d4066a
pandas/core/dtypes/cast.py
@@ -185,7 +185,16 @@ def maybe_downcast_to_dtype(result, dtype: Dtype):
185
# a datetimelike
186
# GH12821, iNaT is cast to float
187
if dtype.kind in ["M", "m"] and result.dtype.kind in ["i", "f"]:
188
- result = result.astype(dtype)
+ if is_datetime_or_timedelta_dtype(dtype):
189
+ result = result.astype(dtype)
190
+ else:
191
+ # not a numpy dtype
192
+ if dtype.tz:
193
+ # convert to datetime and change timezone
194
+ from pandas import to_datetime
195
+
196
+ result = to_datetime(result).tz_localize("utc")
197
+ result = result.tz_convert(dtype.tz)
198
199
return result
200
0 commit comments