26
26
27
27
from pandas .core .dtypes .cast import (
28
28
construct_1d_arraylike_from_scalar ,
29
+ dict_compat ,
29
30
maybe_cast_to_datetime ,
30
31
maybe_convert_platform ,
31
32
maybe_infer_to_datetimelike ,
59
60
TimedeltaArray ,
60
61
)
61
62
from pandas .core .construction import (
62
- create_series_with_explicit_dtype ,
63
63
ensure_wrapped_if_datetimelike ,
64
64
extract_array ,
65
65
range_to_ndarray ,
66
66
sanitize_array ,
67
67
)
68
68
from pandas .core .indexes import base as ibase
69
69
from pandas .core .indexes .api import (
70
+ DatetimeIndex ,
70
71
Index ,
72
+ TimedeltaIndex ,
71
73
ensure_index ,
72
74
get_objs_combined_axis ,
73
75
union_indexes ,
@@ -556,6 +558,7 @@ def convert(v):
556
558
557
559
558
560
def _homogenize (data , index : Index , dtype : DtypeObj | None ) -> list [ArrayLike ]:
561
+ oindex = None
559
562
homogenized = []
560
563
561
564
for val in data :
@@ -570,9 +573,18 @@ def _homogenize(data, index: Index, dtype: DtypeObj | None) -> list[ArrayLike]:
570
573
val = val ._values
571
574
else :
572
575
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 )
576
588
577
589
val = sanitize_array (
578
590
val , index , dtype = dtype , copy = False , raise_cast_failure = False
0 commit comments