def intersection(self, other): """ Form the intersection of two Index objects. Sortedness of the result is not guaranteed Parameters ---------- other : Index or array-like Returns ------- intersection : Index """ if not hasattr(other, "__iter__"): raise Exception("Input must be iterable!") if self.equals(other): return self other = _ensure_index(other) if other.dtype != np.object_: other = other.astype(object) if self.is_monotonic and other.is_monotonic: return Index(lib.inner_join_indexer_object(self, other)[0]) else: indexer = self.get_indexer(other) indexer = indexer.take((indexer != -1).nonzero()[0]) return self.take(indexer)
def _join_monotonic(self, other, how='left', return_indexers=False): this_vals = self.values if self.dtype != other.dtype: other = Index(other, dtype=object) other_vals = other.values if how == 'left': join_index = self lidx = None ridx = lib.left_join_indexer_object(self, other) elif how == 'right': join_index = other lidx = lib.left_join_indexer_object(other, self) ridx = None elif how == 'inner': join_index, lidx, ridx = lib.inner_join_indexer_object(this_vals, other_vals) join_index = self._wrap_joined_index(join_index, other) elif how == 'outer': join_index, lidx, ridx = lib.outer_join_indexer_object(this_vals, other_vals) join_index = self._wrap_joined_index(join_index, other) else: # pragma: no cover raise Exception('do not recognize join method %s' % how) if return_indexers: return join_index, lidx, ridx else: return join_index
def _join_monotonic(self, other, how="left", return_indexers=False): if how == "left": join_index = self lidx = None ridx = lib.left_join_indexer_object(self, other) elif how == "right": join_index = other lidx = lib.left_join_indexer_object(other, self) ridx = None elif how == "inner": join_index, lidx, ridx = lib.inner_join_indexer_object(self, other) join_index = Index(join_index) elif how == "outer": join_index, lidx, ridx = lib.outer_join_indexer_object(self, other) join_index = Index(join_index) else: # pragma: no cover raise Exception("do not recognize join method %s" % how) if return_indexers: return join_index, lidx, ridx else: return join_index