Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pandas/_libs/lib.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2250,7 +2250,7 @@ def maybe_convert_objects(ndarray[object] objects, bint try_float=False,
break
elif is_timedelta(val):
if convert_timedelta:
itimedeltas[i] = convert_to_timedelta64(val, 'ns')
itimedeltas[i] = convert_to_timedelta64(val, "ns").view("i8")
seen.timedelta_ = True
else:
seen.object_ = True
Expand Down
10 changes: 10 additions & 0 deletions pandas/tests/dtypes/test_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,16 @@ def test_maybe_convert_objects_datetime(self):
out = lib.maybe_convert_objects(arr, convert_datetime=1, convert_timedelta=1)
tm.assert_numpy_array_equal(out, exp)

def test_maybe_convert_objects_timedelta64_nat(self):
obj = np.timedelta64("NaT", "ns")
arr = np.array([obj], dtype=object)
assert arr[0] is obj

result = lib.maybe_convert_objects(arr, convert_timedelta=True)

expected = np.array([obj], dtype="m8[ns]")
tm.assert_numpy_array_equal(result, expected)

@pytest.mark.parametrize(
"exp",
[
Expand Down