Skip to content

Remove address violation with safe_sort #55984

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pandas/core/algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -1630,11 +1630,12 @@ def safe_sort(
if use_na_sentinel:
# take_nd is faster, but only works for na_sentinels of -1
order2 = sorter.argsort()
new_codes = take_nd(order2, codes, fill_value=-1)
if verify:
mask = (codes < -len(values)) | (codes >= len(values))
codes[mask] = 0
else:
mask = None
new_codes = take_nd(order2, codes, fill_value=-1)
else:
reverse_indexer = np.empty(len(sorter), dtype=int)
reverse_indexer.put(sorter, np.arange(len(sorter)))
Expand Down
10 changes: 0 additions & 10 deletions pandas/tests/test_sorting.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@
import numpy as np
import pytest

from pandas.compat import (
is_ci_environment,
is_platform_windows,
)

from pandas import (
NA,
DataFrame,
Expand Down Expand Up @@ -409,11 +404,6 @@ def test_codes(self, verify, codes, exp_codes):
tm.assert_numpy_array_equal(result, expected)
tm.assert_numpy_array_equal(result_codes, expected_codes)

@pytest.mark.skipif(
is_platform_windows() and is_ci_environment(),
reason="In CI environment can crash thread with: "
"Windows fatal exception: access violation",
)
def test_codes_out_of_bound(self):
values = np.array([3, 1, 2, 0, 4])
expected = np.array([0, 1, 2, 3, 4])
Expand Down