(
data, index: Index, dtype: DtypeObj | None
)
| 551 | |
| 552 | |
| 553 | def _homogenize( |
| 554 | data, index: Index, dtype: DtypeObj | None |
| 555 | ) -> tuple[list[ArrayLike], list[Any]]: |
| 556 | oindex = None |
| 557 | homogenized = [] |
| 558 | # if the original array-like in `data` is a Series, keep track of this Series' refs |
| 559 | refs: list[Any] = [] |
| 560 | |
| 561 | for val in data: |
| 562 | if isinstance(val, (ABCSeries, Index)): |
| 563 | if dtype is not None: |
| 564 | val = val.astype(dtype) |
| 565 | if isinstance(val, ABCSeries) and val.index is not index: |
| 566 | # Forces alignment. No need to copy data since we |
| 567 | # are putting it into an ndarray later |
| 568 | val = val.reindex(index) |
| 569 | refs.append(val._references) |
| 570 | val = val._values |
| 571 | else: |
| 572 | if isinstance(val, dict): |
| 573 | # GH#41785 this _should_ be equivalent to (but faster than) |
| 574 | # val = Series(val, index=index)._values |
| 575 | if oindex is None: |
| 576 | oindex = index.astype("O") |
| 577 | |
| 578 | if isinstance(index, (DatetimeIndex, TimedeltaIndex)): |
| 579 | # see test_constructor_dict_datetime64_index |
| 580 | val = dict_compat(val) |
| 581 | else: |
| 582 | # see test_constructor_subclass_dict |
| 583 | val = dict(val) |
| 584 | |
| 585 | if not isinstance(index, MultiIndex) and index.hasnans: |
| 586 | # GH#63889 Check if dict has missing value keys that need special |
| 587 | # handling (i.e. None/np.nan/pd.NA might no longer be matched |
| 588 | # when using fast_multiget with processed object index values) |
| 589 | from pandas import Series |
| 590 | |
| 591 | val = Series(val).reindex(index)._values |
| 592 | else: |
| 593 | # Fast path: use lib.fast_multiget for dicts without missing keys |
| 594 | val = lib.fast_multiget(val, oindex._values, default=np.nan) |
| 595 | |
| 596 | val = sanitize_array(val, index, dtype=dtype, copy=False) |
| 597 | com.require_length_match(val, index) |
| 598 | refs.append(None) |
| 599 | |
| 600 | homogenized.append(val) |
| 601 | |
| 602 | return homogenized, refs |
| 603 | |
| 604 | |
| 605 | def _extract_index(data) -> Index: |
no test coverage detected