@@ -1285,124 +1285,6 @@ def _is_unorderable_exception(e: TypeError) -> bool:
12851285 return "unorderable" in str (e )
12861286
12871287
1288- def is_numeric_v_string_like (a , b ):
1289- """
1290- Check if we are comparing a string-like object to a numeric ndarray.
1291-
1292- NumPy doesn't like to compare such objects, especially numeric arrays
1293- and scalar string-likes.
1294-
1295- Parameters
1296- ----------
1297- a : array-like, scalar
1298- The first object to check.
1299- b : array-like, scalar
1300- The second object to check.
1301-
1302- Returns
1303- -------
1304- boolean
1305- Whether we return a comparing a string-like object to a numeric array.
1306-
1307- Examples
1308- --------
1309- >>> is_numeric_v_string_like(1, 1)
1310- False
1311- >>> is_numeric_v_string_like("foo", "foo")
1312- False
1313- >>> is_numeric_v_string_like(1, "foo") # non-array numeric
1314- False
1315- >>> is_numeric_v_string_like(np.array([1]), "foo")
1316- True
1317- >>> is_numeric_v_string_like("foo", np.array([1])) # symmetric check
1318- True
1319- >>> is_numeric_v_string_like(np.array([1, 2]), np.array(["foo"]))
1320- True
1321- >>> is_numeric_v_string_like(np.array(["foo"]), np.array([1, 2]))
1322- True
1323- >>> is_numeric_v_string_like(np.array([1]), np.array([2]))
1324- False
1325- >>> is_numeric_v_string_like(np.array(["foo"]), np.array(["foo"]))
1326- False
1327- """
1328-
1329- is_a_array = isinstance (a , np .ndarray )
1330- is_b_array = isinstance (b , np .ndarray )
1331-
1332- is_a_numeric_array = is_a_array and is_numeric_dtype (a )
1333- is_b_numeric_array = is_b_array and is_numeric_dtype (b )
1334- is_a_string_array = is_a_array and is_string_like_dtype (a )
1335- is_b_string_array = is_b_array and is_string_like_dtype (b )
1336-
1337- is_a_scalar_string_like = not is_a_array and isinstance (a , str )
1338- is_b_scalar_string_like = not is_b_array and isinstance (b , str )
1339-
1340- return (
1341- (is_a_numeric_array and is_b_scalar_string_like )
1342- or (is_b_numeric_array and is_a_scalar_string_like )
1343- or (is_a_numeric_array and is_b_string_array )
1344- or (is_b_numeric_array and is_a_string_array )
1345- )
1346-
1347-
1348- def is_datetimelike_v_numeric (a , b ):
1349- """
1350- Check if we are comparing a datetime-like object to a numeric object.
1351-
1352- By "numeric," we mean an object that is either of an int or float dtype.
1353-
1354- Parameters
1355- ----------
1356- a : array-like, scalar
1357- The first object to check.
1358- b : array-like, scalar
1359- The second object to check.
1360-
1361- Returns
1362- -------
1363- boolean
1364- Whether we return a comparing a datetime-like to a numeric object.
1365-
1366- Examples
1367- --------
1368- >>> dt = np.datetime64(pd.datetime(2017, 1, 1))
1369- >>>
1370- >>> is_datetimelike_v_numeric(1, 1)
1371- False
1372- >>> is_datetimelike_v_numeric(dt, dt)
1373- False
1374- >>> is_datetimelike_v_numeric(1, dt)
1375- True
1376- >>> is_datetimelike_v_numeric(dt, 1) # symmetric check
1377- True
1378- >>> is_datetimelike_v_numeric(np.array([dt]), 1)
1379- True
1380- >>> is_datetimelike_v_numeric(np.array([1]), dt)
1381- True
1382- >>> is_datetimelike_v_numeric(np.array([dt]), np.array([1]))
1383- True
1384- >>> is_datetimelike_v_numeric(np.array([1]), np.array([2]))
1385- False
1386- >>> is_datetimelike_v_numeric(np.array([dt]), np.array([dt]))
1387- False
1388- """
1389-
1390- if not hasattr (a , "dtype" ):
1391- a = np .asarray (a )
1392- if not hasattr (b , "dtype" ):
1393- b = np .asarray (b )
1394-
1395- def is_numeric (x ):
1396- """
1397- Check if an object has a numeric dtype (i.e. integer or float).
1398- """
1399- return is_integer_dtype (x ) or is_float_dtype (x )
1400-
1401- return (needs_i8_conversion (a ) and is_numeric (b )) or (
1402- needs_i8_conversion (b ) and is_numeric (a )
1403- )
1404-
1405-
14061288def needs_i8_conversion (arr_or_dtype ):
14071289 """
14081290 Check whether the array or dtype should be converted to int64.
0 commit comments