Extracts the union from lvals and rvals with respect to duplicates and nans in both arrays. Parameters ---------- lvals: np.ndarray or ExtensionArray left values which is ordered in front. rvals: np.ndarray or ExtensionArray right values ordered after lvals.
(
lvals: ArrayLike | Index, rvals: ArrayLike | Index
)
| 1588 | |
| 1589 | |
| 1590 | def union_with_duplicates( |
| 1591 | lvals: ArrayLike | Index, rvals: ArrayLike | Index |
| 1592 | ) -> ArrayLike | Index: |
| 1593 | """ |
| 1594 | Extracts the union from lvals and rvals with respect to duplicates and nans in |
| 1595 | both arrays. |
| 1596 | |
| 1597 | Parameters |
| 1598 | ---------- |
| 1599 | lvals: np.ndarray or ExtensionArray |
| 1600 | left values which is ordered in front. |
| 1601 | rvals: np.ndarray or ExtensionArray |
| 1602 | right values ordered after lvals. |
| 1603 | |
| 1604 | Returns |
| 1605 | ------- |
| 1606 | np.ndarray or ExtensionArray |
| 1607 | Containing the unsorted union of both arrays. |
| 1608 | |
| 1609 | Notes |
| 1610 | ----- |
| 1611 | Caller is responsible for ensuring lvals.dtype == rvals.dtype. |
| 1612 | """ |
| 1613 | from pandas import Series |
| 1614 | |
| 1615 | l_count = value_counts_internal(lvals, dropna=False) |
| 1616 | r_count = value_counts_internal(rvals, dropna=False) |
| 1617 | l_count, r_count = l_count.align(r_count, fill_value=0) |
| 1618 | final_count = np.maximum(l_count.values, r_count.values) |
| 1619 | final_count = Series(final_count, index=l_count.index, dtype="int", copy=False) |
| 1620 | if isinstance(lvals, ABCMultiIndex) and isinstance(rvals, ABCMultiIndex): |
| 1621 | unique_vals = lvals.append(rvals).unique() |
| 1622 | else: |
| 1623 | if isinstance(lvals, ABCIndex): |
| 1624 | lvals = lvals._values |
| 1625 | if isinstance(rvals, ABCIndex): |
| 1626 | rvals = rvals._values |
| 1627 | # error: List item 0 has incompatible type "Union[ExtensionArray, |
| 1628 | # ndarray[Any, Any], Index]"; expected "Union[ExtensionArray, |
| 1629 | # ndarray[Any, Any]]" |
| 1630 | combined = concat_compat([lvals, rvals]) # type: ignore[list-item] |
| 1631 | unique_vals = unique(combined) |
| 1632 | unique_vals = ensure_wrapped_if_datetimelike(unique_vals) |
| 1633 | repeats = final_count.reindex(unique_vals).values |
| 1634 | return np.repeat(unique_vals, repeats) |
| 1635 | |
| 1636 | |
| 1637 | def map_array( |
nothing calls this directly
no test coverage detected