Skip to content

Conversation

@mtsokol
Copy link
Contributor

@mtsokol mtsokol commented Aug 4, 2023

Hi!
Due to NumPy's main namespace being changed in numpy/numpy#24316, here I update warning imports. Please share your feedback!

@google-cla
Copy link

google-cla bot commented Aug 4, 2023

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@mtsokol mtsokol force-pushed the update-np-exceptions-imports branch from 69adc51 to 736a95a Compare August 4, 2023 14:53
Copy link
Collaborator

@hawkinsp hawkinsp left a comment

Choose a reason for hiding this comment

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

Thanks for the PR!

@google-ml-butler google-ml-butler bot added kokoro:force-run pull ready Ready for copybara import and testing labels Aug 4, 2023
Copy link
Collaborator

@hawkinsp hawkinsp left a comment

Choose a reason for hiding this comment

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

Looks like there are some test failures from using numpy_version when numpy_version() should be used.

Copy link
Collaborator

@jakevdp jakevdp left a comment

Choose a reason for hiding this comment

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

Looks good - thanks for looking into this!

One suggestion – rather than the version check, what if we used a try...except?

try:
  # numpy 1.25.0 or newer
  NumpyComplexWarning = np.exceptions.ComplexWarning
except AttributeError:
  # legacy numpy
  NumpyComplexWarning = np.ComplexWarning

Version checks are fine for tests, but I'd prefer to avoid them in package import paths – e.g. imagine a user who has some custom numpy build with a version string that we don't anticipate, and then import jax might fail on trying to cast the version to a tuple of ints.

jax/_src/util.py Outdated
if numpy_version() >= (1, 25, 0):
ComplexWarning = np.exceptions.ComplexWarning
else:
ComplexWarning = np.ComplexWarning
Copy link
Collaborator

Choose a reason for hiding this comment

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

What if we named this NumpyComplexWarning from the start to avoid the need to rename the imports?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure! I renamed it.

@jakevdp jakevdp self-assigned this Aug 4, 2023
@mtsokol
Copy link
Contributor Author

mtsokol commented Aug 4, 2023

Hi @jakevdp @hawkinsp!

Sure! I will add these changes. For the version check I followed scipy codebase but try makes more sense.


Also, I wanted to want to keep you in the loop on the progress of NEP 52, which will influence NumPy's API.

In this issue there's an ongoing discussion about changes in the main namespace: numpy/numpy#24306 (comment) (in the details of this comment there is a remove/tentative/keep list of main namespace items). Your feedback will be extremely valuable for me!

@jakevdp
Copy link
Collaborator

jakevdp commented Aug 4, 2023

Thanks for pointing to NEP 52. Everything looks pretty straightforward, but one thing I'm confused about is the dtype sized alias thing.

If I am referencing np.float64 now, what would I use in the future? np.dtypes.float64 instead?

@mtsokol
Copy link
Contributor Author

mtsokol commented Aug 4, 2023

Thanks for pointing to NEP 52. Everything looks pretty straightforward, but one thing I'm confused about is the dtype sized alias thing.

If I am referencing np.float64 now, what would I use in the future? np.dtypes.float64 instead?

Current status is that sized aliases are kept in the same place and only "other aliases" mentioned in NumPy docs are being removed.

@mtsokol
Copy link
Contributor Author

mtsokol commented Aug 7, 2023

Looks like there are some test failures from using numpy_version when numpy_version() should be used.

Yes, I moved back to a version where numpy_version is already a version tuple.

Copy link
Collaborator

@jakevdp jakevdp left a comment

Choose a reason for hiding this comment

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

Looks good - one more comment below.

After that, please also squash your changes into a single commit (see https://jax.readthedocs.io/en/latest/contributing.html#single-change-commits-and-pull-requests)

@mtsokol mtsokol force-pushed the update-np-exceptions-imports branch 2 times, most recently from e20b0e0 to fa4342a Compare August 7, 2023 16:30
@mtsokol mtsokol force-pushed the update-np-exceptions-imports branch from f3b17ee to d183a2c Compare August 7, 2023 17:09
@mtsokol mtsokol requested a review from jakevdp August 7, 2023 17:11
@copybara-service copybara-service bot merged commit e219456 into jax-ml:main Aug 7, 2023
@mtsokol mtsokol deleted the update-np-exceptions-imports branch August 7, 2023 20:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pull ready Ready for copybara import and testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants