def _get_single_indexer(join_key, index, sort=False): left_key, right_key, count = _factorize_keys(join_key, index, sort=sort) left_indexer, right_indexer = lib.left_outer_join( com._ensure_int64(left_key), com._ensure_int64(right_key), count, sort=sort ) return left_indexer, right_indexer
def _get_single_indexer(join_key, index, sort=False): left_key, right_key, count = _factorize_keys(join_key, index, sort=sort) left_indexer, right_indexer = \ lib.left_outer_join(com._ensure_int64(left_key), com._ensure_int64(right_key), count, sort=sort) return left_indexer, right_indexer
def _get_multiindex_indexer(join_keys, index, sort=False): shape = [] labels = [] for level, key in zip(index.levels, join_keys): llab, rlab, count = _factorize_keys(level, key, sort=False) labels.append(rlab) shape.append(count) left_group_key = get_group_index(labels, shape) right_group_key = get_group_index(index.labels, shape) left_group_key, right_group_key, max_groups = _factorize_keys(left_group_key, right_group_key, sort=False) left_indexer, right_indexer = lib.left_outer_join( com._ensure_int64(left_group_key), com._ensure_int64(right_group_key), max_groups, sort=False ) return left_indexer, right_indexer
def test_left_outer_join_bug(): left = np.array([0, 1, 0, 1, 1, 2, 3, 1, 0, 2, 1, 2, 0, 1, 1, 2, 3, 2, 3, 2, 1, 1, 3, 0, 3, 2, 3, 0, 0, 2, 3, 2, 0, 3, 1, 3, 0, 1, 3, 0, 0, 1, 0, 3, 1, 0, 1, 0, 1, 1, 0, 2, 2, 2, 2, 2, 0, 3, 1, 2, 0, 0, 3, 1, 3, 2, 2, 0, 1, 3, 0, 2, 3, 2, 3, 3, 2, 3, 3, 1, 3, 2, 0, 0, 3, 1, 1, 1, 0, 2, 3, 3, 1, 2, 0, 3, 1, 2, 0, 2], dtype=np.int64) right = np.array([3, 1], dtype=np.int64) max_groups = 4 lidx, ridx = lib.left_outer_join(left, right, max_groups, sort=False) exp_lidx = np.arange(len(left)) exp_ridx = -np.ones(len(left)) exp_ridx[left == 1] = 1 exp_ridx[left == 3] = 0 assert(np.array_equal(lidx, exp_lidx)) assert(np.array_equal(ridx, exp_ridx))
def _get_multiindex_indexer(join_keys, index, sort=False): shape = [] labels = [] for level, key in zip(index.levels, join_keys): llab, rlab, count = _factorize_keys(level, key, sort=False) labels.append(rlab) shape.append(count) left_group_key = get_group_index(labels, shape) right_group_key = get_group_index(index.labels, shape) left_group_key, right_group_key, max_groups = \ _factorize_keys(left_group_key, right_group_key, sort=False) left_indexer, right_indexer = \ lib.left_outer_join(com._ensure_int64(left_group_key), com._ensure_int64(right_group_key), max_groups, sort=False) return left_indexer, right_indexer
def test_left_outer_join_bug(): left = np.array([ 0, 1, 0, 1, 1, 2, 3, 1, 0, 2, 1, 2, 0, 1, 1, 2, 3, 2, 3, 2, 1, 1, 3, 0, 3, 2, 3, 0, 0, 2, 3, 2, 0, 3, 1, 3, 0, 1, 3, 0, 0, 1, 0, 3, 1, 0, 1, 0, 1, 1, 0, 2, 2, 2, 2, 2, 0, 3, 1, 2, 0, 0, 3, 1, 3, 2, 2, 0, 1, 3, 0, 2, 3, 2, 3, 3, 2, 3, 3, 1, 3, 2, 0, 0, 3, 1, 1, 1, 0, 2, 3, 3, 1, 2, 0, 3, 1, 2, 0, 2 ], dtype=np.int64) right = np.array([3, 1], dtype=np.int64) max_groups = 4 lidx, ridx = lib.left_outer_join(left, right, max_groups, sort=False) exp_lidx = np.arange(len(left)) exp_ridx = -np.ones(len(left)) exp_ridx[left == 1] = 1 exp_ridx[left == 3] = 0 assert (np.array_equal(lidx, exp_lidx)) assert (np.array_equal(ridx, exp_ridx))
def _right_outer_join(x, y, max_groups): right_indexer, left_indexer = lib.left_outer_join(y, x, max_groups) return left_indexer, right_indexer