Skip to content

Commit 1efc2d7

Browse files
authored
CLN: Partially revert #29553 (#51137)
* CLN: Partially revert #29553 * fix tests * Update missing.py
1 parent 9bd15db commit 1efc2d7

File tree

5 files changed

+2
-100
lines changed

5 files changed

+2
-100
lines changed

pandas/core/array_algos/replace.py

+1-12
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
)
2020

2121
from pandas.core.dtypes.common import (
22-
is_datetimelike_v_numeric,
23-
is_numeric_v_string_like,
2422
is_re,
2523
is_re_compilable,
2624
is_scalar,
@@ -44,7 +42,7 @@ def should_use_regex(regex: bool, to_replace: Any) -> bool:
4442

4543
def compare_or_regex_search(
4644
a: ArrayLike, b: Scalar | Pattern, regex: bool, mask: npt.NDArray[np.bool_]
47-
) -> ArrayLike | bool:
45+
) -> ArrayLike:
4846
"""
4947
Compare two array-like inputs of the same shape or two scalar values
5048
@@ -95,15 +93,6 @@ def _check_comparison_types(
9593
if isinstance(a, np.ndarray):
9694
a = a[mask]
9795

98-
if is_numeric_v_string_like(a, b):
99-
# GH#29553 avoid deprecation warnings from numpy
100-
return np.zeros(a.shape, dtype=bool)
101-
102-
elif is_datetimelike_v_numeric(a, b):
103-
# GH#29553 avoid deprecation warnings from numpy
104-
_check_comparison_types(False, a, b)
105-
return False
106-
10796
result = op(a)
10897

10998
if isinstance(result, np.ndarray) and mask is not None:

pandas/core/dtypes/common.py

-60
Original file line numberDiff line numberDiff line change
@@ -1067,64 +1067,6 @@ def is_numeric_v_string_like(a: ArrayLike, b) -> bool:
10671067
)
10681068

10691069

1070-
# This exists to silence numpy deprecation warnings, see GH#29553
1071-
def is_datetimelike_v_numeric(a, b) -> bool:
1072-
"""
1073-
Check if we are comparing a datetime-like object to a numeric object.
1074-
By "numeric," we mean an object that is either of an int or float dtype.
1075-
1076-
Parameters
1077-
----------
1078-
a : array-like, scalar
1079-
The first object to check.
1080-
b : array-like, scalar
1081-
The second object to check.
1082-
1083-
Returns
1084-
-------
1085-
boolean
1086-
Whether we return a comparing a datetime-like to a numeric object.
1087-
1088-
Examples
1089-
--------
1090-
>>> from datetime import datetime
1091-
>>> dt = np.datetime64(datetime(2017, 1, 1))
1092-
>>>
1093-
>>> is_datetimelike_v_numeric(1, 1)
1094-
False
1095-
>>> is_datetimelike_v_numeric(dt, dt)
1096-
False
1097-
>>> is_datetimelike_v_numeric(1, dt)
1098-
True
1099-
>>> is_datetimelike_v_numeric(dt, 1) # symmetric check
1100-
True
1101-
>>> is_datetimelike_v_numeric(np.array([dt]), 1)
1102-
True
1103-
>>> is_datetimelike_v_numeric(np.array([1]), dt)
1104-
True
1105-
>>> is_datetimelike_v_numeric(np.array([dt]), np.array([1]))
1106-
True
1107-
>>> is_datetimelike_v_numeric(np.array([1]), np.array([2]))
1108-
False
1109-
>>> is_datetimelike_v_numeric(np.array([dt]), np.array([dt]))
1110-
False
1111-
"""
1112-
if not hasattr(a, "dtype"):
1113-
a = np.asarray(a)
1114-
if not hasattr(b, "dtype"):
1115-
b = np.asarray(b)
1116-
1117-
def is_numeric(x):
1118-
"""
1119-
Check if an object has a numeric dtype (i.e. integer or float).
1120-
"""
1121-
return is_integer_dtype(x) or is_float_dtype(x)
1122-
1123-
return (needs_i8_conversion(a) and is_numeric(b)) or (
1124-
needs_i8_conversion(b) and is_numeric(a)
1125-
)
1126-
1127-
11281070
def needs_i8_conversion(arr_or_dtype) -> bool:
11291071
"""
11301072
Check whether the array or dtype should be converted to int64.
@@ -1790,7 +1732,6 @@ def is_all_strings(value: ArrayLike) -> bool:
17901732
"is_datetime64_dtype",
17911733
"is_datetime64_ns_dtype",
17921734
"is_datetime64tz_dtype",
1793-
"is_datetimelike_v_numeric",
17941735
"is_datetime_or_timedelta_dtype",
17951736
"is_decimal",
17961737
"is_dict_like",
@@ -1809,7 +1750,6 @@ def is_all_strings(value: ArrayLike) -> bool:
18091750
"is_number",
18101751
"is_numeric_dtype",
18111752
"is_any_numeric_dtype",
1812-
"is_numeric_v_string_like",
18131753
"is_object_dtype",
18141754
"is_period_dtype",
18151755
"is_re",

pandas/core/dtypes/missing.py

-7
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
is_bool_dtype,
2929
is_categorical_dtype,
3030
is_complex_dtype,
31-
is_datetimelike_v_numeric,
3231
is_dtype_equal,
3332
is_extension_array_dtype,
3433
is_float_dtype,
@@ -505,8 +504,6 @@ def array_equivalent(
505504
# fastpath when we require that the dtypes match (Block.equals)
506505
if left.dtype.kind in ["f", "c"]:
507506
return _array_equivalent_float(left, right)
508-
elif is_datetimelike_v_numeric(left.dtype, right.dtype):
509-
return False
510507
elif needs_i8_conversion(left.dtype):
511508
return _array_equivalent_datetimelike(left, right)
512509
elif is_string_or_object_np_dtype(left.dtype):
@@ -529,10 +526,6 @@ def array_equivalent(
529526
return True
530527
return ((left == right) | (isna(left) & isna(right))).all()
531528

532-
elif is_datetimelike_v_numeric(left, right):
533-
# GH#29553 avoid numpy deprecation warning
534-
return False
535-
536529
elif needs_i8_conversion(left.dtype) or needs_i8_conversion(right.dtype):
537530
# datetime64, timedelta64, Period
538531
if not is_dtype_equal(left.dtype, right.dtype):

pandas/core/internals/blocks.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -677,10 +677,7 @@ def replace_list(
677677
# GH#38086 faster if we know we dont need to check for regex
678678
masks = [missing.mask_missing(values, s[0]) for s in pairs]
679679

680-
# error: Argument 1 to "extract_bool_array" has incompatible type
681-
# "Union[ExtensionArray, ndarray, bool]"; expected "Union[ExtensionArray,
682-
# ndarray]"
683-
masks = [extract_bool_array(x) for x in masks] # type: ignore[arg-type]
680+
masks = [extract_bool_array(x) for x in masks]
684681

685682
rb = [self if inplace else self.copy()]
686683
for i, (src, dest) in enumerate(pairs):

pandas/tests/dtypes/test_common.py

-17
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
from __future__ import annotations
22

3-
from datetime import datetime
4-
53
import numpy as np
64
import pytest
75

@@ -517,21 +515,6 @@ def test_is_numeric_v_string_like():
517515
assert com.is_numeric_v_string_like(np.array(["foo"]), np.array([1, 2]))
518516

519517

520-
def test_is_datetimelike_v_numeric():
521-
dt = np.datetime64(datetime(2017, 1, 1))
522-
523-
assert not com.is_datetimelike_v_numeric(1, 1)
524-
assert not com.is_datetimelike_v_numeric(dt, dt)
525-
assert not com.is_datetimelike_v_numeric(np.array([1]), np.array([2]))
526-
assert not com.is_datetimelike_v_numeric(np.array([dt]), np.array([dt]))
527-
528-
assert com.is_datetimelike_v_numeric(1, dt)
529-
assert com.is_datetimelike_v_numeric(1, dt)
530-
assert com.is_datetimelike_v_numeric(np.array([dt]), 1)
531-
assert com.is_datetimelike_v_numeric(np.array([1]), dt)
532-
assert com.is_datetimelike_v_numeric(np.array([dt]), np.array([1]))
533-
534-
535518
def test_needs_i8_conversion():
536519
assert not com.needs_i8_conversion(str)
537520
assert not com.needs_i8_conversion(np.int64)

0 commit comments

Comments
 (0)