Skip to content
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

adapt to NEP 51 #8064

Merged
merged 6 commits into from
Sep 25, 2023
Merged

adapt to NEP 51 #8064

merged 6 commits into from
Sep 25, 2023

Conversation

keewis
Copy link
Collaborator

@keewis keewis commented Aug 10, 2023

With NEP 51 (and the changes to numpy main), scalar types no longer pretend to be standard python types in their string representation. This fixes most of the errors in the tests but there are still a few remaining in the doctests (in particular, doctests for private plotting utils).

@dcherian
Copy link
Contributor

Should we keep the numpy representation since that's more accurate?

We could use pytest-accept to update the tests

@keewis
Copy link
Collaborator Author

keewis commented Aug 10, 2023

Should we keep the numpy representation since that's more accurate?

I wouldn't think so, but I might be wrong: we already have the dtype information right beside it so it wouldn't add much, and they are usually taken out of arrays and are only formatted that way because we iterate over the array's values.

That said, there are definitely a few instances where we actually do return numpy scalars in the doctests that should be updated (although that means we'd have to wait until we adopt numpy>1.25 (numpy=2.0?), and accept that you have to use at least that version to run the doctests until we can discontinue support for numpy<2.0)

@headtr1ck
Copy link
Collaborator

That said, there are definitely a few instances where we actually do return numpy scalars in the doctests that should be updated (although that means we'd have to wait until we adopt numpy>1.25 (numpy=2.0?), and accept that you have to use at least that version to run the doctests until we can discontinue support for numpy<2.0)

You could also parse them to python floats/ints before displaying them. This would work with all numpy versions.

@keewis
Copy link
Collaborator Author

keewis commented Aug 11, 2023

You could also parse them to python floats/ints before displaying them.

Cast, you mean?

@headtr1ck
Copy link
Collaborator

Simply value = float(da.item()). This will display the same for all np versions.

@keewis keewis added the run-upstream Run upstream CI label Sep 15, 2023
@keewis
Copy link
Collaborator Author

keewis commented Sep 20, 2023

Simply value = float(da.item())

The float wouldn't even be necessary, arr.item() (and arr.tolist()) always return python types.

However, for some we're not the ones who issue those (an example: fg.axs[0, 0].get_xlim() in xarray.plot.facetgrid.FacetGrid._set_lims returns a tuple of two numpy.floats, but get_xlim is from matplotlib).

According to numpy/numpy#24470, the recommendation is to test a single numpy version, so I'd worry about those once numpy=2.0 has been released (we could also switch to a more advanced doctest runner like pytest-doctestplus, but that should be a new PR).

@keewis
Copy link
Collaborator Author

keewis commented Sep 20, 2023

this should now be ready for merging, and the rolling failures is an issue upstream in dask (see #8091)

@keewis keewis added the plan to merge Final call for comments label Sep 24, 2023
@headtr1ck headtr1ck merged commit bac90ab into pydata:main Sep 25, 2023
@keewis keewis deleted the scalar-repr branch September 30, 2023 09:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
plan to merge Final call for comments run-upstream Run upstream CI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants