Skip to content

Commit

Permalink
DEPR: move NumericIndex._convert_tolerance to Index (#50932)
Browse files Browse the repository at this point in the history
* DEPR: move NumericIndex._convert_tolerance to Index

* fix error message
  • Loading branch information
topper-123 authored Jan 25, 2023
1 parent 7f2aa8f commit 74b13fa
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 16 deletions.
11 changes: 11 additions & 0 deletions pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 0 additions & 16 deletions pandas/core/indexes/numeric.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Expand Down

0 comments on commit 74b13fa

Please sign in to comment.