Skip to content

Commit 447cef2

Browse files
committed
clean up if condition
1 parent 5c129d8 commit 447cef2

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

pandas/core/dtypes/cast.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
is_datetime64_dtype,
5454
is_datetime64_ns_dtype,
5555
is_datetime64tz_dtype,
56+
is_datetime_or_timedelta_any_dtype,
5657
is_datetime_or_timedelta_dtype,
5758
is_dtype_equal,
5859
is_extension_array_dtype,
@@ -175,9 +176,9 @@ def maybe_downcast_to_dtype(result, dtype: Dtype):
175176
return converted
176177

177178
# a datetimelike
178-
# 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"):
179+
# GH12821, iNaT is cast to float
180+
if is_datetime_or_timedelta_any_dtype(dtype) and result.dtype.kind in ["i", "f"]:
181+
if not is_datetime_or_timedelta_dtype(dtype):
181182
# not a numpy dtype
182183
if dtype.tz:
183184
# convert to datetime and change timezone

0 commit comments

Comments
 (0)