MCPcopy
hub / github.com/pandas-dev/pandas / union_with_duplicates

Function union_with_duplicates

pandas/core/algorithms.py:1590–1634  ·  view source on GitHub ↗

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
)

Source from the content-addressed store, hash-verified

1588
1589
1590def 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
1637def map_array(

Callers

nothing calls this directly

Calls 10

reindexMethod · 0.95
SeriesClass · 0.90
concat_compatFunction · 0.90
value_counts_internalFunction · 0.85
uniqueFunction · 0.85
alignMethod · 0.80
uniqueMethod · 0.45
appendMethod · 0.45
repeatMethod · 0.45

Tested by

no test coverage detected