diff --git a/pandas/_libs/lib.pyi b/pandas/_libs/lib.pyi index 3e14bf12c43f8..b39d32d069619 100644 --- a/pandas/_libs/lib.pyi +++ b/pandas/_libs/lib.pyi @@ -231,7 +231,7 @@ def is_range_indexer( left: np.ndarray, n: int, # np.ndarray[np.int64, ndim=1] ) -> bool: ... -def is_range( +def is_sequence_range( sequence: np.ndarray, - diff: int, # np.ndarray[np.int64, ndim=1] + step: int, # np.ndarray[np.int64, ndim=1] ) -> bool: ... diff --git a/pandas/_libs/lib.pyx b/pandas/_libs/lib.pyx index 8412d3b4fd0e7..0780c4f0c454c 100644 --- a/pandas/_libs/lib.pyx +++ b/pandas/_libs/lib.pyx @@ -680,19 +680,19 @@ def is_range_indexer(ndarray[int6432_t, ndim=1] left, Py_ssize_t n) -> bool: @cython.wraparound(False) @cython.boundscheck(False) -def is_range(ndarray[int6432_t, ndim=1] sequence, int64_t diff) -> bool: +def is_sequence_range(ndarray[intp_t, ndim=1] sequence, int64_t step) -> bool: """ - Check if sequence is equivalent to a range with the specified diff. + Check if sequence is equivalent to a range with the specified step. """ cdef: Py_ssize_t i, n = len(sequence) - if diff == 0: + if step == 0: return False for i in range(n): - if sequence[i] != sequence[0] + i * diff: + if sequence[i] != sequence[0] + i * step: return False return True diff --git a/pandas/core/indexes/range.py b/pandas/core/indexes/range.py index 64c855347dc7a..2e7c3a1ad6e01 100644 --- a/pandas/core/indexes/range.py +++ b/pandas/core/indexes/range.py @@ -482,7 +482,7 @@ def _shallow_copy(self, values, name: Hashable = no_default): new_range = range(start, start + self.step, self.step) return type(self)._simple_new(new_range, name=name) diff = values[1] - values[0] - if not missing.isna(diff) and lib.is_range(values, diff): + if not missing.isna(diff) and lib.is_sequence_range(values, diff): new_range = range(values[0], values[-1] + diff, diff) return type(self)._simple_new(new_range, name=name) return self._constructor._simple_new(values, name=name)