@@ -1100,15 +1100,15 @@ def is_datetime_or_timedelta_dtype(arr_or_dtype) -> bool:
1100
1100
1101
1101
1102
1102
# This exists to silence numpy deprecation warnings, see GH#29553
1103
- def is_numeric_v_string_like (a , b ):
1103
+ def is_numeric_v_string_like (a : ArrayLike , b ):
1104
1104
"""
1105
1105
Check if we are comparing a string-like object to a numeric ndarray.
1106
1106
NumPy doesn't like to compare such objects, especially numeric arrays
1107
1107
and scalar string-likes.
1108
1108
1109
1109
Parameters
1110
1110
----------
1111
- a : array-like, scalar
1111
+ a : array-like
1112
1112
The first object to check.
1113
1113
b : array-like, scalar
1114
1114
The second object to check.
@@ -1120,16 +1120,8 @@ def is_numeric_v_string_like(a, b):
1120
1120
1121
1121
Examples
1122
1122
--------
1123
- >>> is_numeric_v_string_like(1, 1)
1124
- False
1125
- >>> is_numeric_v_string_like("foo", "foo")
1126
- False
1127
- >>> is_numeric_v_string_like(1, "foo") # non-array numeric
1128
- False
1129
1123
>>> is_numeric_v_string_like(np.array([1]), "foo")
1130
1124
True
1131
- >>> is_numeric_v_string_like("foo", np.array([1])) # symmetric check
1132
- True
1133
1125
>>> is_numeric_v_string_like(np.array([1, 2]), np.array(["foo"]))
1134
1126
True
1135
1127
>>> is_numeric_v_string_like(np.array(["foo"]), np.array([1, 2]))
@@ -1142,17 +1134,15 @@ def is_numeric_v_string_like(a, b):
1142
1134
is_a_array = isinstance (a , np .ndarray )
1143
1135
is_b_array = isinstance (b , np .ndarray )
1144
1136
1145
- is_a_numeric_array = is_a_array and is_numeric_dtype ( a )
1146
- is_b_numeric_array = is_b_array and is_numeric_dtype ( b )
1147
- is_a_string_array = is_a_array and is_string_like_dtype ( a )
1148
- is_b_string_array = is_b_array and is_string_like_dtype ( b )
1137
+ is_a_numeric_array = is_a_array and a . dtype . kind in ( "u" , "i" , "f" , "c" , "b" )
1138
+ is_b_numeric_array = is_b_array and b . dtype . kind in ( "u" , "i" , "f" , "c" , "b" )
1139
+ is_a_string_array = is_a_array and a . dtype . kind in ( "S" , "U" )
1140
+ is_b_string_array = is_b_array and b . dtype . kind in ( "S" , "U" )
1149
1141
1150
- is_a_scalar_string_like = not is_a_array and isinstance (a , str )
1151
1142
is_b_scalar_string_like = not is_b_array and isinstance (b , str )
1152
1143
1153
1144
return (
1154
1145
(is_a_numeric_array and is_b_scalar_string_like )
1155
- or (is_b_numeric_array and is_a_scalar_string_like )
1156
1146
or (is_a_numeric_array and is_b_string_array )
1157
1147
or (is_b_numeric_array and is_a_string_array )
1158
1148
)
@@ -1305,37 +1295,6 @@ def is_numeric_dtype(arr_or_dtype) -> bool:
1305
1295
)
1306
1296
1307
1297
1308
- def is_string_like_dtype (arr_or_dtype ) -> bool :
1309
- """
1310
- Check whether the provided array or dtype is of a string-like dtype.
1311
-
1312
- Unlike `is_string_dtype`, the object dtype is excluded because it
1313
- is a mixed dtype.
1314
-
1315
- Parameters
1316
- ----------
1317
- arr_or_dtype : array-like
1318
- The array or dtype to check.
1319
-
1320
- Returns
1321
- -------
1322
- boolean
1323
- Whether or not the array or dtype is of the string dtype.
1324
-
1325
- Examples
1326
- --------
1327
- >>> is_string_like_dtype(str)
1328
- True
1329
- >>> is_string_like_dtype(object)
1330
- False
1331
- >>> is_string_like_dtype(np.array(['a', 'b']))
1332
- True
1333
- >>> is_string_like_dtype(pd.Series([1, 2]))
1334
- False
1335
- """
1336
- return _is_dtype (arr_or_dtype , lambda dtype : dtype .kind in ("S" , "U" ))
1337
-
1338
-
1339
1298
def is_float_dtype (arr_or_dtype ) -> bool :
1340
1299
"""
1341
1300
Check whether the provided array or dtype is of a float dtype.
0 commit comments