def test_pad(self): old = Index([1, 5, 10]) new = Index(range(12)) filler = lib.pad_int64(old, new, old.indexMap, new.indexMap) expect_filler = [-1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2] self.assert_(np.array_equal(filler, expect_filler)) # corner case old = Index([5, 10]) new = Index(range(5)) filler = lib.pad_int64(old, new, old.indexMap, new.indexMap) expect_filler = [-1, -1, -1, -1, -1] self.assert_(np.array_equal(filler, expect_filler))
def get_indexer(self, target, method=None): target = _ensure_index(target) if self.dtype != target.dtype: this = Index(self, dtype=object) target = Index(target, dtype=object) return this.get_indexer(target, method=method) method = self._get_method(method) if method == "pad": indexer = lib.pad_int64(self, target, self.indexMap, target.indexMap) elif method == "backfill": indexer = lib.backfill_int64(self, target, self.indexMap, target.indexMap) elif method is None: indexer = lib.merge_indexer_int64(target, self.indexMap) else: # pragma: no cover raise ValueError("unrecognized method: %s" % method) return indexer