Skip to content

Commit 524150c

Browse files
committed
Issue pandas-dev#30520 more readable code + specifically check for NaT
1 parent 9d751b9 commit 524150c

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

pandas/core/common.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,12 @@ def maybe_box(indexer, values, obj, key):
8383
def maybe_box_datetimelike(value):
8484
# turn a datetime like into a Timestamp/timedelta as needed
8585

86-
if isinstance(value, (np.datetime64, datetime)) and (
87-
not isinstance(value, tslibs.Timestamp)) and (
88-
notnull(value)):
86+
if isinstance(value, (tslibs.Timedelta, tslibs.Timestamp)) or value is tslibs.NaT:
87+
return value
88+
89+
if isinstance(value, (np.datetime64, datetime)):
8990
value = tslibs.Timestamp(value)
90-
elif isinstance(value, (np.timedelta64, timedelta)) and (
91-
not isinstance(value, tslibs.Timedelta)) and (
92-
notnull(value)):
91+
elif isinstance(value, (np.timedelta64, timedelta)):
9392
value = tslibs.Timedelta(value)
9493

9594
return value

0 commit comments

Comments
 (0)