From 74b13fa8996f796cc487ebb12ef97e826386dd4d Mon Sep 17 00:00:00 2001 From: Terji Petersen Date: Wed, 25 Jan 2023 20:51:44 +0000 Subject: [PATCH] DEPR: move NumericIndex._convert_tolerance to Index (#50932) * DEPR: move NumericIndex._convert_tolerance to Index * fix error message --- pandas/core/indexes/base.py | 11 +++++++++++ pandas/core/indexes/numeric.py | 16 ---------------- 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 2f5b1ec6b6ffd..50f0597772cd9 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -3811,6 +3811,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 6834fdcdf1f99..4d5e527728567 100644 --- a/pandas/core/indexes/numeric.py +++ b/pandas/core/indexes/numeric.py @@ -190,22 +190,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: """