Skip to content

MultiIndex union/intersection with non-object other #32646

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 17, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions pandas/core/indexes/multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -3235,9 +3235,13 @@ def union(self, other, sort=None):

# TODO: Index.union returns other when `len(self)` is 0.

uniq_tuples = lib.fast_unique_multiple(
[self._values, other._ndarray_values], sort=sort
)
if not is_object_dtype(other.dtype):
raise NotImplementedError(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this hit in any tests?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, can add one

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add one

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added+green (though no azure)

"Can only union MultiIndex with MultiIndex or Index of tuples, "
"try mi.to_flat_index().union(other) instead."
)

uniq_tuples = lib.fast_unique_multiple([self._values, other._values], sort=sort)

return MultiIndex.from_arrays(
zip(*uniq_tuples), sortorder=0, names=result_names
Expand Down Expand Up @@ -3271,8 +3275,18 @@ def intersection(self, other, sort=False):
if self.equals(other):
return self

if not is_object_dtype(other.dtype):
# The intersection is empty
# TODO: we have no tests that get here
return MultiIndex(
levels=self.levels,
codes=[[]] * self.nlevels,
names=result_names,
verify_integrity=False,
)

lvals = self._values
rvals = other._ndarray_values
rvals = other._values

uniq_tuples = None # flag whether _inner_indexer was succesful
if self.is_monotonic and other.is_monotonic:
Expand Down