Skip to content

Commit 2677166

Browse files
committed
Make sort_tuples last resort sorting strategy to allow faster sorters to execute first
1 parent 225675d commit 2677166

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

pandas/core/algorithms.py

+16-9
Original file line numberDiff line numberDiff line change
@@ -1023,10 +1023,11 @@ def checked_add_with_arr(arr, b, arr_mask=None, b_mask=None):
10231023
to_raise = ((np.iinfo(np.int64).max - b2 < arr) & not_nan).any()
10241024
else:
10251025
to_raise = (
1026-
(np.iinfo(np.int64).max - b2[mask1] < arr[mask1]) & not_nan[mask1]
1027-
).any() or (
1028-
(np.iinfo(np.int64).min - b2[mask2] > arr[mask2]) & not_nan[mask2]
1029-
).any()
1026+
((np.iinfo(np.int64).max - b2[mask1] < arr[mask1]) & not_nan[mask1]).any()
1027+
or (
1028+
(np.iinfo(np.int64).min - b2[mask2] > arr[mask2]) & not_nan[mask2]
1029+
).any()
1030+
)
10301031

10311032
if to_raise:
10321033
raise OverflowError("Overflow in int64 addition")
@@ -2095,18 +2096,24 @@ def cmp_func(index_x, index_y):
20952096

20962097
sorter = None
20972098

2098-
is_ea = is_extension_array_dtype(values)
2099-
if not is_ea and lib.infer_dtype(values, skipna=False) == "mixed-integer":
2099+
if (
2100+
not is_extension_array_dtype(values)
2101+
and lib.infer_dtype(values, skipna=False) == "mixed-integer"
2102+
):
21002103
ordered = sort_mixed(values)
2101-
elif not is_ea and values.size and isinstance(values[0], tuple):
2102-
ordered = sort_tuples(values)
21032104
else:
21042105
try:
21052106
sorter = values.argsort()
21062107
ordered = values.take(sorter)
21072108
except TypeError:
21082109
# try this anyway
2109-
ordered = sort_mixed(values)
2110+
try:
2111+
ordered = sort_mixed(values)
2112+
except TypeError:
2113+
if values.size and isinstance(values[0], tuple):
2114+
ordered = sort_tuples(values)
2115+
else:
2116+
raise
21102117

21112118
# codes:
21122119

0 commit comments

Comments
 (0)