@@ -1191,6 +1191,124 @@ def _is_unorderable_exception(e: TypeError) -> bool:
11911191 return "'>' not supported between instances of" in str (e )
11921192
11931193
1194+ # This exists to silence numpy deprecation warnings, see GH#29553
1195+ def is_numeric_v_string_like (a , b ):
1196+ """
1197+ Check if we are comparing a string-like object to a numeric ndarray.
1198+ NumPy doesn't like to compare such objects, especially numeric arrays
1199+ and scalar string-likes.
1200+
1201+ Parameters
1202+ ----------
1203+ a : array-like, scalar
1204+ The first object to check.
1205+ b : array-like, scalar
1206+ The second object to check.
1207+
1208+ Returns
1209+ -------
1210+ boolean
1211+ Whether we return a comparing a string-like object to a numeric array.
1212+
1213+ Examples
1214+ --------
1215+ >>> is_numeric_v_string_like(1, 1)
1216+ False
1217+ >>> is_numeric_v_string_like("foo", "foo")
1218+ False
1219+ >>> is_numeric_v_string_like(1, "foo") # non-array numeric
1220+ False
1221+ >>> is_numeric_v_string_like(np.array([1]), "foo")
1222+ True
1223+ >>> is_numeric_v_string_like("foo", np.array([1])) # symmetric check
1224+ True
1225+ >>> is_numeric_v_string_like(np.array([1, 2]), np.array(["foo"]))
1226+ True
1227+ >>> is_numeric_v_string_like(np.array(["foo"]), np.array([1, 2]))
1228+ True
1229+ >>> is_numeric_v_string_like(np.array([1]), np.array([2]))
1230+ False
1231+ >>> is_numeric_v_string_like(np.array(["foo"]), np.array(["foo"]))
1232+ False
1233+ """
1234+
1235+ is_a_array = isinstance (a , np .ndarray )
1236+ is_b_array = isinstance (b , np .ndarray )
1237+
1238+ is_a_numeric_array = is_a_array and is_numeric_dtype (a )
1239+ is_b_numeric_array = is_b_array and is_numeric_dtype (b )
1240+ is_a_string_array = is_a_array and is_string_like_dtype (a )
1241+ is_b_string_array = is_b_array and is_string_like_dtype (b )
1242+
1243+ is_a_scalar_string_like = not is_a_array and isinstance (a , str )
1244+ is_b_scalar_string_like = not is_b_array and isinstance (b , str )
1245+
1246+ return (
1247+ (is_a_numeric_array and is_b_scalar_string_like )
1248+ or (is_b_numeric_array and is_a_scalar_string_like )
1249+ or (is_a_numeric_array and is_b_string_array )
1250+ or (is_b_numeric_array and is_a_string_array )
1251+ )
1252+
1253+
1254+ # This exists to silence numpy deprecation warnings, see GH#29553
1255+ def is_datetimelike_v_numeric (a , b ):
1256+ """
1257+ Check if we are comparing a datetime-like object to a numeric object.
1258+ By "numeric," we mean an object that is either of an int or float dtype.
1259+
1260+ Parameters
1261+ ----------
1262+ a : array-like, scalar
1263+ The first object to check.
1264+ b : array-like, scalar
1265+ The second object to check.
1266+
1267+ Returns
1268+ -------
1269+ boolean
1270+ Whether we return a comparing a datetime-like to a numeric object.
1271+
1272+ Examples
1273+ --------
1274+ >>> dt = np.datetime64(pd.datetime(2017, 1, 1))
1275+ >>>
1276+ >>> is_datetimelike_v_numeric(1, 1)
1277+ False
1278+ >>> is_datetimelike_v_numeric(dt, dt)
1279+ False
1280+ >>> is_datetimelike_v_numeric(1, dt)
1281+ True
1282+ >>> is_datetimelike_v_numeric(dt, 1) # symmetric check
1283+ True
1284+ >>> is_datetimelike_v_numeric(np.array([dt]), 1)
1285+ True
1286+ >>> is_datetimelike_v_numeric(np.array([1]), dt)
1287+ True
1288+ >>> is_datetimelike_v_numeric(np.array([dt]), np.array([1]))
1289+ True
1290+ >>> is_datetimelike_v_numeric(np.array([1]), np.array([2]))
1291+ False
1292+ >>> is_datetimelike_v_numeric(np.array([dt]), np.array([dt]))
1293+ False
1294+ """
1295+
1296+ if not hasattr (a , "dtype" ):
1297+ a = np .asarray (a )
1298+ if not hasattr (b , "dtype" ):
1299+ b = np .asarray (b )
1300+
1301+ def is_numeric (x ):
1302+ """
1303+ Check if an object has a numeric dtype (i.e. integer or float).
1304+ """
1305+ return is_integer_dtype (x ) or is_float_dtype (x )
1306+
1307+ return (needs_i8_conversion (a ) and is_numeric (b )) or (
1308+ needs_i8_conversion (b ) and is_numeric (a )
1309+ )
1310+
1311+
11941312def needs_i8_conversion (arr_or_dtype ) -> bool :
11951313 """
11961314 Check whether the array or dtype should be converted to int64.
0 commit comments