Skip to content

BUG: #31993: Return FAIL if PyArray_ClipmodeConverter is called with an invalid integer value.#31996

Open
stestagg wants to merge 1 commit into
numpy:mainfrom
stestagg:gh-31993
Open

BUG: #31993: Return FAIL if PyArray_ClipmodeConverter is called with an invalid integer value.#31996
stestagg wants to merge 1 commit into
numpy:mainfrom
stestagg:gh-31993

Conversation

@stestagg

@stestagg stestagg commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

PR summary

PyArray_ClipmodeConverter sets the exception if an invalid value is passed but, for numbers, also returned NPY_SUCCEED.

Python in debug mode catches this and aserts/aborts.

Returning NPY_FAIL correctly propagates the exception at the right point.

Before this change, the new test caused spin test to
silently fail with exit code 250.

Test output tail
numpy/_core/tests/test_casting_unittests.py::TestCasting::test_same_value_naninf[nan] PASSED                                                                        [  3%]
numpy/_core/tests/test_casting_unittests.py::TestCasting::test_same_value_naninf[inf] PASSED                                                                        [  3%]
numpy/_core/tests/test_casting_unittests.py::TestCasting::test_same_value_naninf[-inf] PASSED                                                                       [  3%]
numpy/_core/tests/test_casting_unittests.py::TestCasting::test_same_value_complex PASSED                                                                            [  3%]
numpy/_core/tests/test_casting_unittests.py::TestCasting::test_same_value_scalar PASSED                                                                             [  3%]
numpy/_core/tests/test_conversion_utils.py::TestByteorderConverter::test_wrong_type PASSED                                                                          [  3%]
numpy/_core/tests/test_conversion_utils.py::TestByteorderConverter::test_wrong_value PASSED                                                                         [  3%]
numpy/_core/tests/test_conversion_utils.py::TestByteorderConverter::test_valid PASSED                                                                               [  3%]
numpy/_core/tests/test_conversion_utils.py::TestSortkindConverter::test_wrong_type PASSED                                                                           [  3%]
numpy/_core/tests/test_conversion_utils.py::TestSortkindConverter::test_wrong_value PASSED                                                                          [  3%]
numpy/_core/tests/test_conversion_utils.py::TestSortkindConverter::test_valid PASSED                                                                                [  3%]
numpy/_core/tests/test_conversion_utils.py::TestSelectkindConverter::test_wrong_type PASSED                                                                         [  3%]
numpy/_core/tests/test_conversion_utils.py::TestSelectkindConverter::test_wrong_value PASSED                                                                        [  3%]
numpy/_core/tests/test_conversion_utils.py::TestSelectkindConverter::test_valid PASSED                                                                              [  3%]
numpy/_core/tests/test_conversion_utils.py::TestSearchsideConverter::test_wrong_type PASSED                                                                         [  3%]
numpy/_core/tests/test_conversion_utils.py::TestSearchsideConverter::test_wrong_value PASSED                                                                        [  3%]
numpy/_core/tests/test_conversion_utils.py::TestSearchsideConverter::test_valid PASSED                                                                              [  3%]
numpy/_core/tests/test_conversion_utils.py::TestOrderConverter::test_wrong_type PASSED                                                                              [  3%]
numpy/_core/tests/test_conversion_utils.py::TestOrderConverter::test_wrong_value PASSED                                                                             [  3%]
numpy/_core/tests/test_conversion_utils.py::TestOrderConverter::test_valid PASSED                                                                                   [  3%]
numpy/_core/tests/test_conversion_utils.py::TestOrderConverter::test_flatten_invalid_order PASSED                                                                   [  3%]
numpy/_core/tests/test_conversion_utils.py::TestClipmodeConverter::test_wrong_type PASSED                                                                           [  3%]
numpy/_core/tests/test_conversion_utils.py::TestClipmodeConverter::test_wrong_value PASSED                                                                          [  3%]
numpy/_core/tests/test_conversion_utils.py::TestClipmodeConverter::test_valid PASSED                                                                                [  3%]
numpy/_core/tests/test_conversion_utils.py::TestClipmodeConverter::test_invalid ⏎
sstagg@sapphire ~/s/numpy [250]>

With the change tests pass as expected.

First time committer introduction

Hi 👋, I've been using numpy since about 2009 maybe, I'm getting to the point where I can do some fuzz testing of pandas on things like json/csv, parquet etc, but along the way, I was checking that numpy would work, and stumbled across this really niche issue, but the fix is so tiny/self-evident I thought I'd get it in.

AI Disclosure

Codex was used in helping identify/debug the initial root cause of the debug abort.

No AI tools were used in the actual development of this PR

Fixed: #31993

…with an invalid integer value.

PyArray_ClipmodeConverter sets the exception if an invalid value
is passed, but for numbers, returned NPY_SUCCEED.

Python in debug mode catches this and aserts/aborts,
returning NPY_FAIL correctly propagates the exception
at the right point.

Before this change, the new test caused spin to
silently fail with exit code 250.  With the change
tests pass as expected.
@tylerjereddy tylerjereddy added the Priority: low Valid, but not for immediate attention label Jul 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Priority: low Valid, but not for immediate attention

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: Debug assert calling np.take with an invalid mode

2 participants