Skip to content

Commit 74b13fa

Browse files
authored
DEPR: move NumericIndex._convert_tolerance to Index (#50932)
* DEPR: move NumericIndex._convert_tolerance to Index * fix error message
1 parent 7f2aa8f commit 74b13fa

File tree

2 files changed

+11
-16
lines changed

2 files changed

+11
-16
lines changed

pandas/core/indexes/base.py

+11
Original file line numberDiff line numberDiff line change
@@ -3811,6 +3811,17 @@ def _convert_tolerance(self, tolerance, target: np.ndarray | Index) -> np.ndarra
38113811
tolerance = np.asarray(tolerance)
38123812
if target.size != tolerance.size and tolerance.size > 1:
38133813
raise ValueError("list-like tolerance size must match target index size")
3814+
elif is_numeric_dtype(self) and not np.issubdtype(tolerance.dtype, np.number):
3815+
if tolerance.ndim > 0:
3816+
raise ValueError(
3817+
f"tolerance argument for {type(self).__name__} with dtype "
3818+
f"{self.dtype} must contain numeric elements if it is list type"
3819+
)
3820+
3821+
raise ValueError(
3822+
f"tolerance argument for {type(self).__name__} with dtype {self.dtype} "
3823+
f"must be numeric if it is a scalar: {repr(tolerance)}"
3824+
)
38143825
return tolerance
38153826

38163827
@final

pandas/core/indexes/numeric.py

-16
Original file line numberDiff line numberDiff line change
@@ -190,22 +190,6 @@ def _maybe_cast_slice_bound(self, label, side: str):
190190

191191
# ----------------------------------------------------------------
192192

193-
def _convert_tolerance(self, tolerance, target):
194-
tolerance = super()._convert_tolerance(tolerance, target)
195-
196-
if not np.issubdtype(tolerance.dtype, np.number):
197-
if tolerance.ndim > 0:
198-
raise ValueError(
199-
f"tolerance argument for {type(self).__name__} must contain "
200-
"numeric elements if it is list type"
201-
)
202-
203-
raise ValueError(
204-
f"tolerance argument for {type(self).__name__} must be numeric "
205-
f"if it is a scalar: {repr(tolerance)}"
206-
)
207-
return tolerance
208-
209193
@classmethod
210194
def _assert_safe_casting(cls, data: np.ndarray, subarr: np.ndarray) -> None:
211195
"""

0 commit comments

Comments
 (0)