예제 #1
0
파일: index.py 프로젝트: npinger/pandas
    def union(self, other):
        if not isinstance(other, Int64Index):
            return Index.union(self.astype(object), other)

        if self.is_monotonic and other.is_monotonic:
            result = lib.outer_join_indexer_int64(self, other)[0]
        else:
            result = np.unique(np.concatenate((self, other)))
        return Int64Index(result)
예제 #2
0
def test_outer_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.outer_join_indexer_int64(a, b)

    index_exp = np.array([0, 1, 2, 3, 4, 5, 7, 9], dtype=np.int64)
    assert_almost_equal(index, index_exp)

    aexp = np.array([-1, 0, 1, 2, 3, 4, -1, -1], dtype=np.int32)
    bexp = np.array([0, -1, -1, 1, -1, 2, 3, 4])
    assert_almost_equal(ares, aexp)
    assert_almost_equal(bres, bexp)
예제 #3
0
def test_outer_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.outer_join_indexer_int64(a, b)

    index_exp = np.array([0, 1, 2, 3, 4, 5, 7, 9], dtype=np.int64)
    assert_almost_equal(index, index_exp)

    aexp = np.array([-1, 0, 1, 2, 3, 4, -1, -1], dtype=np.int32)
    bexp = np.array([0, -1, -1, 1, -1, 2, 3, 4])
    assert_almost_equal(ares, aexp)
    assert_almost_equal(bres, bexp)
예제 #4
0
파일: index.py 프로젝트: npinger/pandas
    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