Skip to content

Commit 06f317e

Browse files
committed
BUG: fix DataFrame(data=[None, 1], dtype='timedelta64[ns]') raising ValueError
1 parent 68d9dca commit 06f317e

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

pandas/core/arrays/timedeltas.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1111,7 +1111,7 @@ def sequence_to_td64ns(
11111111
else:
11121112
mask = np.isnan(data)
11131113

1114-
data = cast_from_unit_vectorized(data, unit or "ns")
1114+
data = cast_from_unit_vectorized(data.ravel(), unit or "ns").reshape(data.shape)
11151115
data[mask] = iNaT
11161116
data = data.view("m8[ns]")
11171117
copy = False

pandas/tests/frame/test_constructors.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2772,6 +2772,14 @@ def test_construction_datetime_resolution_inference(self, cons):
27722772
res_dtype2 = tm.get_dtype(obj2)
27732773
assert res_dtype2 == "M8[us, US/Pacific]", res_dtype2
27742774

2775+
def test_construction_nan_value_timedelta64_dtype(self):
2776+
# GH#60064
2777+
result = DataFrame([None, 1], dtype="timedelta64[ns]")
2778+
expected = DataFrame(
2779+
["NaT", "0 days 00:00:00.000000001"], dtype="timedelta64[ns]"
2780+
)
2781+
tm.assert_frame_equal(result, expected)
2782+
27752783

27762784
class TestDataFrameConstructorIndexInference:
27772785
def test_frame_from_dict_of_series_overlapping_monthly_period_indexes(self):

0 commit comments

Comments
 (0)