diff --git a/pandas/_libs/index.pyi b/pandas/_libs/index.pyi index 9f526dd3fe653..752f339ff31da 100644 --- a/pandas/_libs/index.pyi +++ b/pandas/_libs/index.pyi @@ -18,12 +18,6 @@ class IndexEngine: def is_monotonic_increasing(self) -> bool: ... @property def is_monotonic_decreasing(self) -> bool: ... - def get_backfill_indexer( - self, other: np.ndarray, limit: int | None = ... - ) -> npt.NDArray[np.intp]: ... - def get_pad_indexer( - self, other: np.ndarray, limit: int | None = ... - ) -> npt.NDArray[np.intp]: ... @property def is_mapping_populated(self) -> bool: ... def clear_mapping(self): ... diff --git a/pandas/_libs/index.pyx b/pandas/_libs/index.pyx index cc6a2ad10f020..a25d15dc68f9a 100644 --- a/pandas/_libs/index.pyx +++ b/pandas/_libs/index.pyx @@ -224,12 +224,6 @@ cdef class IndexEngine: cdef _call_monotonic(self, values): return algos.is_monotonic(values, timelike=False) - def get_backfill_indexer(self, other: np.ndarray, limit=None) -> np.ndarray: - return algos.backfill(self.values, other, limit=limit) - - def get_pad_indexer(self, other: np.ndarray, limit=None) -> np.ndarray: - return algos.pad(self.values, other, limit=limit) - cdef _make_hash_table(self, Py_ssize_t n): raise NotImplementedError diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index a8de95cfa72e0..cf253ca598c18 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -3703,13 +3703,14 @@ def _get_fill_indexer( ) if self.is_monotonic_increasing and target.is_monotonic_increasing: - engine_method = ( - self._engine.get_pad_indexer - if method == "pad" - else self._engine.get_backfill_indexer - ) target_values = target._get_engine_target() - indexer = engine_method(target_values, limit) + own_values = self._get_engine_target() + + if method == "pad": + indexer = libalgos.pad(own_values, target_values, limit=limit) + else: + # i.e. "backfill" + indexer = libalgos.backfill(own_values, target_values, limit=limit) else: indexer = self._get_fill_indexer_searchsorted(target, method, limit) if tolerance is not None and len(self): diff --git a/pandas/tests/indexes/test_engines.py b/pandas/tests/indexes/test_engines.py index 45e8e56d46381..785db921dbab4 100644 --- a/pandas/tests/indexes/test_engines.py +++ b/pandas/tests/indexes/test_engines.py @@ -3,13 +3,9 @@ import numpy as np import pytest -from pandas._libs import ( - algos as libalgos, - index as libindex, -) +from pandas._libs import index as libindex import pandas as pd -import pandas._testing as tm @pytest.fixture( @@ -145,30 +141,6 @@ def test_get_loc(self, numeric_indexing_engine_type_and_dtype): result = engine.get_loc(2) assert (result == expected).all() - def test_get_backfill_indexer(self, numeric_indexing_engine_type_and_dtype): - engine_type, dtype = numeric_indexing_engine_type_and_dtype - - arr = np.array([1, 5, 10], dtype=dtype) - engine = engine_type(arr) - - new = np.arange(12, dtype=dtype) - result = engine.get_backfill_indexer(new) - - expected = libalgos.backfill(arr, new) - tm.assert_numpy_array_equal(result, expected) - - def test_get_pad_indexer(self, numeric_indexing_engine_type_and_dtype): - engine_type, dtype = numeric_indexing_engine_type_and_dtype - - arr = np.array([1, 5, 10], dtype=dtype) - engine = engine_type(arr) - - new = np.arange(12, dtype=dtype) - result = engine.get_pad_indexer(new) - - expected = libalgos.pad(arr, new) - tm.assert_numpy_array_equal(result, expected) - class TestObjectEngine: engine_type = libindex.ObjectEngine @@ -225,23 +197,3 @@ def test_get_loc(self): expected = np.array([False, True, False] * num, dtype=bool) result = engine.get_loc("b") assert (result == expected).all() - - def test_get_backfill_indexer(self): - arr = np.array(["a", "e", "j"], dtype=self.dtype) - engine = self.engine_type(arr) - - new = np.array(list("abcdefghij"), dtype=self.dtype) - result = engine.get_backfill_indexer(new) - - expected = libalgos.backfill["object"](arr, new) - tm.assert_numpy_array_equal(result, expected) - - def test_get_pad_indexer(self): - arr = np.array(["a", "e", "j"], dtype=self.dtype) - engine = self.engine_type(arr) - - new = np.array(list("abcdefghij"), dtype=self.dtype) - result = engine.get_pad_indexer(new) - - expected = libalgos.pad["object"](arr, new) - tm.assert_numpy_array_equal(result, expected)