Skip to content

Commit 22002c0

Browse files
committed
clean up if condition
1 parent be1d6c8 commit 22002c0

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

pandas/core/dtypes/cast.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
is_datetime64_dtype,
4141
is_datetime64_ns_dtype,
4242
is_datetime64tz_dtype,
43+
is_datetime_or_timedelta_any_dtype,
4344
is_datetime_or_timedelta_dtype,
4445
is_dtype_equal,
4546
is_extension_array_dtype,
@@ -160,9 +161,9 @@ def maybe_downcast_to_dtype(result, dtype):
160161
return converted
161162

162163
# a datetimelike
163-
# GH12821, iNaT is casted to float
164-
if dtype.kind in ["M", "m"] and result.dtype.kind in ["i", "f"]:
165-
if hasattr(dtype, "tz"):
164+
# GH12821, iNaT is cast to float
165+
if is_datetime_or_timedelta_any_dtype(dtype) and result.dtype.kind in ["i", "f"]:
166+
if not is_datetime_or_timedelta_dtype(dtype):
166167
# not a numpy dtype
167168
if dtype.tz:
168169
# convert to datetime and change timezone

0 commit comments

Comments
 (0)