diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 2948bb81d0b6a..04a0afedc1a75 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -3780,6 +3780,17 @@ def _convert_tolerance(self, tolerance, target: np.ndarray | Index) -> np.ndarra tolerance = np.asarray(tolerance) if target.size != tolerance.size and tolerance.size > 1: raise ValueError("list-like tolerance size must match target index size") + elif is_numeric_dtype(self) and not np.issubdtype(tolerance.dtype, np.number): + if tolerance.ndim > 0: + raise ValueError( + f"tolerance argument for {type(self).__name__} with dtype " + f"{self.dtype} must contain numeric elements if it is list type" + ) + + raise ValueError( + f"tolerance argument for {type(self).__name__} with dtype {self.dtype} " + f"must be numeric if it is a scalar: {repr(tolerance)}" + ) return tolerance @final diff --git a/pandas/core/indexes/numeric.py b/pandas/core/indexes/numeric.py index 68bdd1893c77f..cd621b64c886e 100644 --- a/pandas/core/indexes/numeric.py +++ b/pandas/core/indexes/numeric.py @@ -221,22 +221,6 @@ def _maybe_cast_slice_bound(self, label, side: str): # ---------------------------------------------------------------- - def _convert_tolerance(self, tolerance, target): - tolerance = super()._convert_tolerance(tolerance, target) - - if not np.issubdtype(tolerance.dtype, np.number): - if tolerance.ndim > 0: - raise ValueError( - f"tolerance argument for {type(self).__name__} must contain " - "numeric elements if it is list type" - ) - - raise ValueError( - f"tolerance argument for {type(self).__name__} must be numeric " - f"if it is a scalar: {repr(tolerance)}" - ) - return tolerance - @classmethod def _assert_safe_casting(cls, data: np.ndarray, subarr: np.ndarray) -> None: """