2626
2727from pandas .core .dtypes .cast import (
2828 construct_1d_arraylike_from_scalar ,
29+ dict_compat ,
2930 maybe_cast_to_datetime ,
3031 maybe_convert_platform ,
3132 maybe_infer_to_datetimelike ,
5960 TimedeltaArray ,
6061)
6162from pandas .core .construction import (
62- create_series_with_explicit_dtype ,
6363 ensure_wrapped_if_datetimelike ,
6464 extract_array ,
6565 range_to_ndarray ,
6666 sanitize_array ,
6767)
6868from pandas .core .indexes import base as ibase
6969from pandas .core .indexes .api import (
70+ DatetimeIndex ,
7071 Index ,
72+ TimedeltaIndex ,
7173 ensure_index ,
7274 get_objs_combined_axis ,
7375 union_indexes ,
@@ -556,6 +558,7 @@ def convert(v):
556558
557559
558560def _homogenize (data , index : Index , dtype : DtypeObj | None ) -> list [ArrayLike ]:
561+ oindex = None
559562 homogenized = []
560563
561564 for val in data :
@@ -570,9 +573,18 @@ def _homogenize(data, index: Index, dtype: DtypeObj | None) -> list[ArrayLike]:
570573 val = val ._values
571574 else :
572575 if isinstance (val , dict ):
573- # see test_constructor_subclass_dict
574- # test_constructor_dict_datetime64_index
575- val = create_series_with_explicit_dtype (val , index = index )._values
576+ # GH#41785 this _should_ be equivalent to (but faster than)
577+ # val = create_series_with_explicit_dtype(val, index=index)._values
578+ if oindex is None :
579+ oindex = index .astype ("O" )
580+
581+ if isinstance (index , (DatetimeIndex , TimedeltaIndex )):
582+ # see test_constructor_dict_datetime64_index
583+ val = dict_compat (val )
584+ else :
585+ # see test_constructor_subclass_dict
586+ val = dict (val )
587+ val = lib .fast_multiget (val , oindex ._values , default = np .nan )
576588
577589 val = sanitize_array (
578590 val , index , dtype = dtype , copy = False , raise_cast_failure = False
0 commit comments