Skip to content

Commit 76b63b5

Browse files
committed
BUG: series from dict of Timedelta scalar drops nanoseconds
(#GH38032) use convert_scalar_for_putitemlike for better conversion
1 parent e4cf3ab commit 76b63b5

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

pandas/core/dtypes/cast.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,7 @@
8888
ABCSeries,
8989
)
9090
from pandas.core.dtypes.inference import is_list_like
91-
from pandas.core.dtypes.missing import (
92-
is_valid_nat_for_dtype,
93-
isna,
94-
na_value_for_dtype,
95-
notna,
96-
)
91+
from pandas.core.dtypes.missing import isna, na_value_for_dtype, notna
9792

9893
if TYPE_CHECKING:
9994
from pandas import Series
@@ -1697,11 +1692,10 @@ def construct_1d_arraylike_from_scalar(
16971692
dtype = np.dtype("object")
16981693
if not isna(value):
16991694
value = ensure_str(value)
1700-
elif dtype.kind in ["M", "m"] and is_valid_nat_for_dtype(value, dtype):
1701-
# GH36541: can't fill array directly with pd.NaT
1702-
# > np.empty(10, dtype="datetime64[64]").fill(pd.NaT)
1703-
# ValueError: cannot convert float NaN to integer
1704-
value = np.datetime64("NaT")
1695+
elif dtype.kind in ["M", "m"]:
1696+
# GH36541: can't fill array directly with pd.NaT -> ValueError
1697+
# GH38032: filling in pd.Timedelta loses nanoseconds
1698+
value = convert_scalar_for_putitemlike(value, dtype)
17051699

17061700
subarr = np.empty(length, dtype=dtype)
17071701
subarr.fill(value)

0 commit comments

Comments
 (0)