Repository navigation
Conversation
Member
|
Thanks, but I'll close this until the discussion on the issue is even somewhat close to a decision that this makes sense. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR summary
Zero-dimensional arrays and NumPy scalar types are documented to support the empty-tuple index
x[()]as a scalar index that returns the scalar value. However,np.str_andnp.bytes_scalars currently raiseTypeErrorwhen indexed withscalar[()], because the index is handled by the underlying Pythonstr/bytesmapping implementation instead of NumPy’s scalar indexing behavior.This change makes
np.str_andnp.bytes_scalars treatscalar[()]as a scalar index and return the scalar value, consistent with other 0‑d NumPy scalars. All other indices are still delegated to the Pythonstr/bytesmapping implementation to preserve existing behavior.In addition, it adds regression tests in
numpy/_core/tests/test_scalarmath.pythat assert:np.str_("abc").shape == ()andnp.str_("abc")[()]returns the samescalar value.
np.bytes_(b"abc").shape == ()andnp.bytes_(b"abc")[()]returnsthe same scalar value.
Fixes gh-31435.
First time committer introduction
Hi, this is my first contribution to NumPy. I use NumPy a lot in my own projects, so I wanted to help improve a library I use a lot and start getting involved in open source development.
AI Disclosure
ChatGPT was used to help make sure this PR is following guidelines. No AI code was used.