Commit 66a2111
authored
BUG: Fix out-of-bounds access in safe_sort with an empty array and non-empty codes (#59489)
* Fix out-of-bounds violations in safe_sort for empty arrays.
Previously we masked `codes` referring to out-of-bounds elements to 0 and
then fixed them after to -1 using `np.putmask`. However, this results in
out-of-bounds access in `take_nd` if the array is empty.
Instead, set all out-of-bounds indices in `codes` to -1 immediately, as
these can be handled by `take_nd`.
* Remove dead code.
`use_na_sentinel` cannot be truthy inside an else branch where it is
falsy.
* Add test based upon #594211 parent 3eb8d34 commit 66a2111
File tree
4 files changed
+21
-11
lines changed- doc/source/whatsnew
- pandas
- core
- tests
- reshape/merge
4 files changed
+21
-11
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
621 | 621 | | |
622 | 622 | | |
623 | 623 | | |
| 624 | + | |
624 | 625 | | |
625 | 626 | | |
626 | 627 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1529 | 1529 | | |
1530 | 1530 | | |
1531 | 1531 | | |
1532 | | - | |
1533 | | - | |
1534 | | - | |
| 1532 | + | |
1535 | 1533 | | |
1536 | 1534 | | |
1537 | 1535 | | |
| |||
1540 | 1538 | | |
1541 | 1539 | | |
1542 | 1540 | | |
1543 | | - | |
1544 | | - | |
1545 | | - | |
1546 | | - | |
1547 | | - | |
1548 | | - | |
1549 | | - | |
1550 | | - | |
1551 | 1541 | | |
1552 | 1542 | | |
1553 | 1543 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2998 | 2998 | | |
2999 | 2999 | | |
3000 | 3000 | | |
| 3001 | + | |
| 3002 | + | |
| 3003 | + | |
| 3004 | + | |
| 3005 | + | |
| 3006 | + | |
| 3007 | + | |
| 3008 | + | |
| 3009 | + | |
| 3010 | + | |
| 3011 | + | |
| 3012 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
408 | 408 | | |
409 | 409 | | |
410 | 410 | | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
411 | 418 | | |
412 | 419 | | |
413 | 420 | | |
| |||
0 commit comments