Esempio n. 1
0
    def intersection(self, other):
        if not isinstance(other, Int64Index):
            return Index.intersection(self.astype(object), other)

        if self.is_monotonic and other.is_monotonic:
            result = lib.inner_join_indexer_int64(self, other)[0]
        else:
            indexer = self.get_indexer(other)
            indexer = indexer.take((indexer != -1).nonzero()[0])
            return self.take(indexer)
        return Int64Index(result)
Esempio n. 2
0
def test_inner_join_indexer():
    a = np.array([1, 2, 3, 4, 5], dtype=np.int64)
    b = np.array([0, 3, 5, 7, 9], dtype=np.int64)

    index, ares, bres = lib.inner_join_indexer_int64(a, b)

    index_exp = np.array([3, 5], dtype=np.int64)
    assert_almost_equal(index, index_exp)

    aexp = np.array([2, 4])
    bexp = np.array([1, 2])
    assert_almost_equal(ares, aexp)
    assert_almost_equal(bres, bexp)
Esempio n. 3
0
def test_inner_join_indexer():
    a = np.array([1, 2, 3, 4, 5], dtype=np.int64)
    b = np.array([0, 3, 5, 7, 9], dtype=np.int64)

    index, ares, bres = lib.inner_join_indexer_int64(a, b)

    index_exp = np.array([3, 5], dtype=np.int64)
    assert_almost_equal(index, index_exp)

    aexp = np.array([2, 4])
    bexp = np.array([1, 2])
    assert_almost_equal(ares, aexp)
    assert_almost_equal(bres, bexp)
Esempio n. 4
0
    def _join_monotonic(self, other, how="left", return_indexers=False):
        if how == "left":
            join_index = self
            lidx = None
            ridx = lib.left_join_indexer_int64(self, other)
        elif how == "right":
            join_index = other
            lidx = lib.left_join_indexer_int64(other, self)
            ridx = None
        elif how == "inner":
            join_index, lidx, ridx = lib.inner_join_indexer_int64(self, other)
            join_index = Int64Index(join_index)
        elif how == "outer":
            join_index, lidx, ridx = lib.outer_join_indexer_int64(self, other)
            join_index = Int64Index(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