Skip to content

Fix test failures with NumPy 2.1 upgrade#76155

Merged
copybara-service[bot] merged 1 commit into
masterfrom
exported_pr_676587056
Sep 20, 2024
Merged

Fix test failures with NumPy 2.1 upgrade#76155
copybara-service[bot] merged 1 commit into
masterfrom
exported_pr_676587056

Conversation

@copybara-service
Copy link
Copy Markdown

Fix test failures with NumPy 2.1 upgrade

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.

@copybara-service copybara-service Bot force-pushed the exported_pr_676587056 branch 4 times, most recently from fb93bb0 to c99effd Compare September 20, 2024 20:20
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
@copybara-service copybara-service Bot force-pushed the exported_pr_676587056 branch from c99effd to 168aa9f Compare September 20, 2024 20:54
@copybara-service copybara-service Bot closed this Sep 20, 2024
@copybara-service copybara-service Bot deleted the exported_pr_676587056 branch September 20, 2024 20:54
@copybara-service copybara-service Bot merged commit 168aa9f into master Sep 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant