Ejemplo n.º 1
0
 def test_get_indexer_limit(self):
     # GH 28631
     idx = RangeIndex(4)
     target = RangeIndex(6)
     result = idx.get_indexer(target, method="pad", limit=1)
     expected = np.array([0, 1, 2, 3, 3, -1], dtype=np.intp)
     tm.assert_numpy_array_equal(result, expected)
Ejemplo n.º 2
0
    def test_engineless_lookup(self):
        # GH 16685
        # Standard lookup on RangeIndex should not require the engine to be
        # created
        idx = RangeIndex(2, 10, 3)

        assert idx.get_loc(5) == 1
        tm.assert_numpy_array_equal(idx.get_indexer([2, 8]),
                                    ensure_platform_int(np.array([0, 2])))
        with pytest.raises(KeyError):
            idx.get_loc(3)

        assert '_engine' not in idx._cache

        # The engine is still required for lookup of a different dtype scalar:
        with pytest.raises(KeyError):
            assert idx.get_loc('a') == -1

        assert '_engine' in idx._cache
Ejemplo n.º 3
0
    def test_engineless_lookup(self):
        # GH 16685
        # Standard lookup on RangeIndex should not require the engine to be
        # created
        idx = RangeIndex(2, 10, 3)

        assert idx.get_loc(5) == 1
        tm.assert_numpy_array_equal(idx.get_indexer([2, 8]),
                                    ensure_platform_int(np.array([0, 2])))
        with pytest.raises(KeyError, match="3"):
            idx.get_loc(3)

        assert "_engine" not in idx._cache

        # Different types of scalars can be excluded immediately, no need to
        #  use the _engine
        with pytest.raises(KeyError, match="'a'"):
            idx.get_loc("a")

        assert "_engine" not in idx._cache
Ejemplo n.º 4
0
 def test_get_indexer_decreasing(self, stop):
     # GH 28678
     index = RangeIndex(7, stop, -3)
     result = index.get_indexer(range(9))
     expected = np.array([-1, 2, -1, -1, 1, -1, -1, 0, -1], dtype=np.intp)
     tm.assert_numpy_array_equal(result, expected)
 def test_get_indexer(self):
     index = RangeIndex(start=0, stop=20, step=2)
     target = RangeIndex(10)
     indexer = index.get_indexer(target)
     expected = np.array([0, -1, 1, -1, 2, -1, 3, -1, 4, -1], dtype=np.intp)
     tm.assert_numpy_array_equal(indexer, expected)
 def test_get_indexer_backfill(self):
     index = RangeIndex(start=0, stop=20, step=2)
     target = RangeIndex(10)
     indexer = index.get_indexer(target, method="backfill")
     expected = np.array([0, 1, 1, 2, 2, 3, 3, 4, 4, 5], dtype=np.intp)
     tm.assert_numpy_array_equal(indexer, expected)