BUG/PERF: algos.union_with_duplicates losing EA dtypes by lukemanley · Pull Request #48900 · pandas-dev/pandas (original) (raw)

I think we need the MultiIndex checks within union_with_duplicates, otherwise we lose dtypes in there. I'm not sure how how this could be done only on the _union level. Let me know if you have any suggestions.

The repeat logic is not quite a simple take:

np.repeat(unique_vals, repeats)

is equivalent to:

indexer = np.arange(len(unique_vals))
indexer = np.repeat(indexer, repeats)
unique_vals.take(indexer)