Skip to content

API: Disallow 0D input arrays in nonzero #26268

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 2 commits into from
Apr 16, 2024
Merged

Conversation

mtsokol
Copy link
Member

@mtsokol mtsokol commented Apr 12, 2024

Fixes #26238

This PR disallows 0D arrays input in np.nonzero and np.ndarray.nonzero.

@mtsokol mtsokol self-assigned this Apr 12, 2024
@mtsokol mtsokol force-pushed the nonzero-0d-input branch 2 times, most recently from b99c53f to 73c033a Compare April 12, 2024 13:55
@mtsokol mtsokol added this to the 2.1.0 release milestone Apr 12, 2024
@charris charris changed the title API: Disallow 0D input arrays in nonzero API: Disallow 0D input arrays in nonzero Apr 12, 2024
Copy link
Member

@seberg seberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code changes, LGTM. Would be good to modify the release fragment and rename (we have an expired category).

@ngoldbaum
Copy link
Member

Thanks Mateusz!

@ngoldbaum ngoldbaum merged commit 75b5bf1 into numpy:main Apr 16, 2024
@mtsokol mtsokol deleted the nonzero-0d-input branch April 16, 2024 15:15
copybara-service bot pushed a commit to tensorflow/tensorflow that referenced this pull request Sep 20, 2024
Create NumPy 1.x and 2.x compatible versions of np.where and np.reshape

np.where: When only condition is provided, np.where(condition) is a shorthand for np.asarray(condition).nonzero(). NumPy 2.1.0rc0 disallows 0D input arrays in nonzero, so np.atleast_1d is used here to remain compatible with NumPy 1.x. See numpy/numpy#26268.

np.reshape: NumPy 2.1.0rc1 added shape and copy arguments to numpy.reshape. Both newshape and shape keywords are supported (use shape as newshape will be deprecated). Besides, shape cannot be None now. To remain behavior with NumPy 1.x, we now use asarray to create an ndarray. See numpy/numpy#26292.

PiperOrigin-RevId: 676587056
copybara-service bot pushed a commit to tensorflow/tensorflow that referenced this pull request Sep 20, 2024
Create NumPy 1.x and 2.x compatible versions of np.where and np.reshape

np.where: When only condition is provided, np.where(condition) is a shorthand for np.asarray(condition).nonzero(). NumPy 2.1.0rc0 disallows 0D input arrays in nonzero, so np.atleast_1d is used here to remain compatible with NumPy 1.x. See numpy/numpy#26268.

np.reshape: NumPy 2.1.0rc1 added shape and copy arguments to numpy.reshape. Both newshape and shape keywords are supported (use shape as newshape will be deprecated). Besides, shape cannot be None now. To remain behavior with NumPy 1.x, we now use asarray to create an ndarray. See numpy/numpy#26292.

PiperOrigin-RevId: 676587056
copybara-service bot pushed a commit to tensorflow/tensorflow that referenced this pull request Sep 20, 2024
Create NumPy 1.x and 2.x compatible versions of np.where and np.reshape

np.where: When only condition is provided, np.where(condition) is a shorthand for np.asarray(condition).nonzero(). NumPy 2.1.0rc0 disallows 0D input arrays in nonzero, so np.atleast_1d is used here to remain compatible with NumPy 1.x. See numpy/numpy#26268.

np.reshape: NumPy 2.1.0rc1 added shape and copy arguments to numpy.reshape. Both newshape and shape keywords are supported (use shape as newshape will be deprecated). Besides, shape cannot be None now. To remain behavior with NumPy 1.x, we now use asarray to create an ndarray. See numpy/numpy#26292.

PiperOrigin-RevId: 676587056
copybara-service bot pushed a commit to tensorflow/tensorflow that referenced this pull request Sep 20, 2024
Create NumPy 1.x and 2.x compatible versions of np.where and np.reshape

np.where: When only condition is provided, np.where(condition) is a shorthand for np.asarray(condition).nonzero(). NumPy 2.1.0rc0 disallows 0D input arrays in nonzero, so np.atleast_1d is used here to remain compatible with NumPy 1.x. See numpy/numpy#26268.

np.reshape: NumPy 2.1.0rc1 added shape and copy arguments to numpy.reshape. Both newshape and shape keywords are supported (use shape as newshape will be deprecated). Besides, shape cannot be None now. To remain behavior with NumPy 1.x, we now use asarray to create an ndarray. See numpy/numpy#26292.

PiperOrigin-RevId: 676587056
copybara-service bot pushed a commit to tensorflow/tensorflow that referenced this pull request Sep 20, 2024
Create NumPy 1.x and 2.x compatible versions of np.where and np.reshape

np.where: When only condition is provided, np.where(condition) is a shorthand for np.asarray(condition).nonzero(). NumPy 2.1.0rc0 disallows 0D input arrays in nonzero, so np.atleast_1d is used here to remain compatible with NumPy 1.x. See numpy/numpy#26268.

np.reshape: NumPy 2.1.0rc1 added shape and copy arguments to numpy.reshape. Both newshape and shape keywords are supported (use shape as newshape will be deprecated). Besides, shape cannot be None now. To remain behavior with NumPy 1.x, we now use asarray to create an ndarray. See numpy/numpy#26292.

PiperOrigin-RevId: 676587056
copybara-service bot pushed a commit to tensorflow/tensorflow that referenced this pull request Sep 20, 2024
Create NumPy 1.x and 2.x compatible versions of np.where and np.reshape

np.where: When only condition is provided, np.where(condition) is a shorthand for np.asarray(condition).nonzero(). NumPy 2.1.0rc0 disallows 0D input arrays in nonzero, so np.atleast_1d is used here to remain compatible with NumPy 1.x. See numpy/numpy#26268.

np.reshape: NumPy 2.1.0rc1 added shape and copy arguments to numpy.reshape. Both newshape and shape keywords are supported (use shape as newshape will be deprecated). Besides, shape cannot be None now. To remain behavior with NumPy 1.x, we now use asarray to create an ndarray. See numpy/numpy#26292.

PiperOrigin-RevId: 676957264
EarlMilktea added a commit to EarlMilktea/cupy that referenced this pull request Oct 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ENH: Should np.nonzero throw exception on 0D input?
3 participants