We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 5c129d8 commit 447cef2Copy full SHA for 447cef2
pandas/core/dtypes/cast.py
@@ -53,6 +53,7 @@
53
is_datetime64_dtype,
54
is_datetime64_ns_dtype,
55
is_datetime64tz_dtype,
56
+ is_datetime_or_timedelta_any_dtype,
57
is_datetime_or_timedelta_dtype,
58
is_dtype_equal,
59
is_extension_array_dtype,
@@ -175,9 +176,9 @@ def maybe_downcast_to_dtype(result, dtype: Dtype):
175
176
return converted
177
178
# a datetimelike
- # GH12821, iNaT is casted to float
179
- if dtype.kind in ["M", "m"] and result.dtype.kind in ["i", "f"]:
180
- if hasattr(dtype, "tz"):
+ # GH12821, iNaT is cast to float
+ if is_datetime_or_timedelta_any_dtype(dtype) and result.dtype.kind in ["i", "f"]:
181
+ if not is_datetime_or_timedelta_dtype(dtype):
182
# not a numpy dtype
183
if dtype.tz:
184
# convert to datetime and change timezone
0 commit comments