File tree Expand file tree Collapse file tree 1 file changed +13
-4
lines changed Expand file tree Collapse file tree 1 file changed +13
-4
lines changed Original file line number Diff line number Diff line change 88
88
ABCSeries ,
89
89
)
90
90
from pandas .core .dtypes .inference import is_list_like
91
- from pandas .core .dtypes .missing import isna , na_value_for_dtype , notna
91
+ from pandas .core .dtypes .missing import (
92
+ is_valid_nat_for_dtype ,
93
+ isna ,
94
+ na_value_for_dtype ,
95
+ notna ,
96
+ )
92
97
93
98
if TYPE_CHECKING :
94
99
from pandas import Series
@@ -1693,9 +1698,13 @@ def construct_1d_arraylike_from_scalar(
1693
1698
if not isna (value ):
1694
1699
value = ensure_str (value )
1695
1700
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 )
1701
+ # GH38032: filling in Timedelta/Timestamp drops nanoseconds
1702
+ if isinstance (value , (Timedelta , Timestamp )):
1703
+ value = value .to_numpy ()
1704
+ # GH36541: filling datetime-like array directly with pd.NaT
1705
+ # raises ValueError: cannot convert float NaN to integer
1706
+ elif is_valid_nat_for_dtype (value , dtype ):
1707
+ value = np .datetime64 ("NaT" )
1699
1708
1700
1709
subarr = np .empty (length , dtype = dtype )
1701
1710
subarr .fill (value )
You can’t perform that action at this time.
0 commit comments