Skip to content

Adjust to numpy dev scalar format - #15065

Merged
pllim merged 27 commits into
astropy:mainfrom
mhvk:adjust-to-numpy-dev-scalar-format
May 29, 2024
Merged

pllim merged 27 commits into
astropy:mainfrom
mhvk:adjust-to-numpy-dev-scalar-format

Conversation

@mhvk

@mhvk mhvk commented Jul 12, 2023 •

Copy link
Copy Markdown
Contributor

DEV NOTE: Do not merge until numpy 2.0 is actually out! Do not merge until this is merged and available in numpy nightly wheel (when we start to see things fail in devdeps)


This is a start to adjusting our tests for the change in how scalars are formatted in NEP 51 - see numpy/numpy#22449

Note that it does not adjust tests of repr and the documentation yet!

Posting this in part to show that outside of repr this is not a big deal.

In the documentation, one often will have things like

>>> q = 5 * u.m
>>> q.value
5.0  -> np.float64(5.0)

This brings up a more general question of whether we should use this opportunity of the repr changing to just return an array scalar (i.e., it would be np.array(5.0) instead). EDIT: this is better discussed elsewhere - see #16508.

Fix #15095
Fix #16491

  • By checking this box, the PR author has requested that maintainers do NOT use the "Squash and Merge" button. Maintainers should respect this when possible; however, the final decision is at the discretion of the maintainer that merges the PR.

@github-actions

Copy link
Copy Markdown
Contributor

Thank you for your contribution to Astropy! 🌌 This checklist is meant to remind the package maintainers who will review this pull request of some common things to look for.

  • Do the proposed changes actually accomplish desired goals?
  • Do the proposed changes follow the Astropy coding guidelines?
  • Are tests added/updated as required? If so, do they follow the Astropy testing guidelines?
  • Are docs added/updated as required? If so, do they follow the Astropy documentation guidelines?
  • Is rebase and/or squash necessary? If so, please provide the author with appropriate instructions. Also see "When to rebase and squash commits".
  • Did the CI pass? If no, are the failures related? If you need to run daily and weekly cron jobs as part of the PR, please apply the "Extra CI" label. Codestyle issues can be fixed by the bot.
  • Is a change log needed? If yes, did the change log check pass? If no, add the "no-changelog-entry-needed" label. If this is a manual backport, use the "skip-changelog-checks" label unless special changelog handling is necessary.
  • Is this a big PR that makes a "What's new?" entry worthwhile and if so, is (1) a "what's new" entry included in this PR and (2) the "whatsnew-needed" label applied?
  • Is a milestone set? Milestone must be set but we cannot check for it on Actions; do not let the green checkmark fool you.
  • At the time of adding the milestone, if the milestone set requires a backport to release branch(es), apply the appropriate "backport-X.Y.x" label(s) before merge.

@github-actions

Copy link
Copy Markdown
Contributor

👋 Thank you for your draft pull request! Do you know that you can use [ci skip] or [skip ci] in your commit messages to skip running continuous integration tests until you are ready?

@pllim

pllim commented Jul 12, 2023

Copy link
Copy Markdown
Member

The diff looks much simpler than I anticipated. Thanks! 🤞

@mhvk

mhvk commented Jul 12, 2023

Copy link
Copy Markdown
Contributor Author

Well, the main diff from the docs is not yet in there...

@pllim

pllim commented Jul 26, 2023

Copy link
Copy Markdown
Member

If #15096 goes in first, that PR also has to be reverted here. FYI.

@mhvk
mhvk force-pushed the adjust-to-numpy-dev-scalar-format branch from 28e80f7 to cf64e6c Compare July 26, 2023 19:16
@mhvk

mhvk commented Jul 26, 2023

Copy link
Copy Markdown
Contributor Author

I just rebased and force-pushed to get a fresh test run. If -dev passes, we probably should run extra CI as well, just in case.

p.s. Very pressed for time right now, so if this doesn't converge easily, happy with #15096 as a stop-gap measure...

@pllim

pllim commented Jul 26, 2023

Copy link
Copy Markdown
Member

Alas... still 95 failed (though 3 of them are from modeling and unrelated).

@pllim

pllim commented Jul 26, 2023

Copy link
Copy Markdown
Member

Looks like we need version check in some places?

ImportError: cannot import name 'get_formatter' from 'numpy.core.arrayprint'

@mhvk

mhvk commented Jul 26, 2023

Copy link
Copy Markdown
Contributor Author

Ah, right, that changed, we didn't make the new get_formatter in the end! Can be a quick change (hopefully)...

@pllim

pllim commented Jul 26, 2023

Copy link
Copy Markdown
Member

There are 51 failures now (3 unrelated, the rest doctest output comparison failures). I actually don't like the new look in our own doc test output... especially when you print out the WCS... it looks jarring and adds noise to the actual data I am interested in (say, what is the value of CVAL1, without also have to see it is np.float because I already know that).

@mhvk

mhvk commented Aug 11, 2023

Copy link
Copy Markdown
Contributor Author

The problem with this PR is that all doctests will fail on older numpy. In principle, we can just not run the tests on older versions, but that makes sense only once 2.0 is actually out. I think the logical route is to go with #15096 first, so that things work again, and then do this one once 2.0 is released.

@pllim

pllim commented Aug 11, 2023

Copy link
Copy Markdown
Member

In that case might even want to wait for numpy 2.1 for a chance for users to catch up? Or is that too long?

Comment thread astropy/units/structured.py Resolved
@mhvk

mhvk commented May 28, 2024

Copy link
Copy Markdown
Contributor Author

@mhvk in Stingray, we've preferred changing all the problematic doctests to asserts. I know that our approach has other problems, but how stable and platform-independent is relying on np.int64 or similar?

I think in the end we are stuck with fixing up after numpy changes here -- which thankfully doesn't happen too often.

In terms of approach, to me, it is important that the documentation actually looks like code one would run, which makes me very hesitant to change just showing output to assert statements. (Of course, I also rather not go again through the rather large hassle of changing all those doctests!)

But if there are more such changes, perhaps we should consider more seriously making the doctest output checks more "sloppy" (like with FLOAT_CMP).

Comment thread pyproject.toml Outdated
"docs/io/fits/index.rst = numpy<1.25", # NUMPY_LT_1_25 (Issue 14545)
"docs/io/fits/usage/image.rst = numpy<1.25", # NUMPY_LT_1_25 (Issue 14545)
"docs/io/fits/usage/unfamiliar.rst = numpy<1.25", # NUMPY_LT_1_25 (Issue 14545)
"docs/* = numpy>=2.0", # not NUMPY_LT_2_0 (PR 15065)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

With this comparison, I think even devdeps won't pick them up, right, because dev is less than stable? How do we know they are actually passing in CI?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

In my first run today, some docs tests failed, so I know it works... See also https://github.com/astropy/astropy/actions/runs/9269807248/job/25501391077?pr=15065#step:7:1464, https://github.com/astropy/astropy/actions/runs/9268687018/job/25497881760?pr=15065#step:10:29371. That makes sense, since those are 2.1.dev

However, you are right that the tests do not run on the 2.0rc (i.e., the prereleases daily cron job). If you think it is worth adjusting this accordingly, then I can do that (my sense is to let it be, given that numpy will be out shortly...)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

OK then the comment to wait for numpy 2.0 still stands, and we'll just not have to merge huge refactoring PRs until then, to ensure rebasing this won't be painful. 🤞

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Because we don't require devdeps to pass to allow merge, and this PR basically is saying that we need devdeps to be green because doctest would only run there until numpy 2 is released.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

OK, maybe that's an argument to change the requirements - I don't really want to have to think about this again...

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I say let's do what we can to merge it now if possible.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

So, is your proposal to change it to numpy>=2.0.dev and then we temporarily make devdeps passing required for merging?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

OK, I changed the requirement to 2.0.0rc1, so we get a real failure if something changes.

@mhvk

mhvk commented May 28, 2024 •

Copy link
Copy Markdown
Contributor Author

Hmm, that's annoying, the fix for boost didn't actually work - see failure in daily cron. Turns out #16431 had not caught all occurrences...

@larrybradley - I redid your fix from #16431 in a different way, which makes everything pass. Could you check the last commit, 840f022 22858d4 4b78dd6?

@mhvk
mhvk force-pushed the adjust-to-numpy-dev-scalar-format branch from 22858d4 to 4b78dd6 Compare May 28, 2024 17:03
@mhvk

mhvk commented May 28, 2024

Copy link
Copy Markdown
Contributor Author

@pllim - the pre-release test in daily cron now indeed includes the doc tests (and passes), so we will get warnings in the unlikely case there is a change to the documentation between now and the official release.

@larrybradley

Copy link
Copy Markdown
Member

@mhvk For sigma_clip, cenfunc and stdfunc can also be input as user-defined callable functions. Do we care if such functions return Python floats? That's why in #16431 I converted all return values from cenfunc and stdfunc into np.float.

@mhvk

mhvk commented May 28, 2024

Copy link
Copy Markdown
Contributor Author

@larrybradley - ah, I see. At some level, no, we do not care - ducktyping is good python practice, after all. And really, even here the only reason we found this is because the doctests cannot both pass with and without bottleneck otherwise. Though of course it is nice if the types astropy itself produces do not depend on what package one happens to have installed!

Anyway, I think I'd leave it as it is now...

@pllim

pllim commented May 28, 2024

Copy link
Copy Markdown
Member

Re: #15065 (comment)

Does this mean the Daily Cron job has to be run now for every PR until numpy 2 is out? 🤔

@mhvk

mhvk commented May 28, 2024

Copy link
Copy Markdown
Contributor Author

Re: #15065 (comment)

Does this mean the Daily Cron job has to be run now for every PR until numpy 2 is out? 🤔

That would be one solution, but so few PRs touch the documentation that I think we could just do without...

Obviously, another option is still just to wait for the actual release.

@pllim

pllim commented May 29, 2024

Copy link
Copy Markdown
Member

We could temporarily add a predeps job to the regular CI as part of this PR, and then make a reminder issue to remove it after. I think we are still a good 3-4 weeks until numpy 2 is released. Not sure if we need remote data though...

- name: Python 3.12 with all optional dependencies and pre-releases
os: ubuntu-latest
python: '3.12'
toxenv: py312-test-alldeps-predeps
toxargs: -v
toxposargs: --remote-data=any

@mhvk

mhvk commented May 29, 2024 •

Copy link
Copy Markdown
Contributor Author

How about I change the double run to use predeps? Maybe not even temporarily: it seems somewhat sensible in general to have a predeps run on our important dependencies.

- name: Python 3.10 Double test (Run tests twice)
linux: py310-test-double

EDIT: possibly make that python 312 as well?

@pllim

pllim commented May 29, 2024

Copy link
Copy Markdown
Member

Double run uses the test runner, it seems. I remember the test runner not very good with doctest (#8153) so not a good candidate.

astropy/tox.ini

Line 120 in 6f217f4

double: python -c 'import sys; from astropy import test; test(); sys.exit(test())'

@mhvk

mhvk commented May 29, 2024

Copy link
Copy Markdown
Contributor Author

OK, I stuck it on the first run with python 3.12 and minimal dependencies.

@mhvk mhvk removed the Extra CI Run cron CI as part of PR label May 29, 2024
@mhvk

mhvk commented May 29, 2024

Copy link
Copy Markdown
Contributor Author

Removed Extra CI since we just checked that worked.

@mhvk
mhvk force-pushed the adjust-to-numpy-dev-scalar-format branch from 7d387fb to 24c6c60 Compare May 29, 2024 15:39
# docs. Fine to remove once numpy 2.0 is released (if problematic).
- name: Python 3.12 with minimal dependencies and full coverage
linux: py312-test-cov
linux: py312-test-cov-predeps

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe this is okay for a few weeks. It is good to have doctest in coverage.

@pllim pllim left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks! My goal is to retire before Numpy 3 or Python 4 comes out, whichever first.

@pllim

pllim commented May 29, 2024

Copy link
Copy Markdown
Member

Thank you so much for going through this pain, @mhvk ! I opened #16512 as a follow-up.

@mhvk

mhvk commented May 29, 2024

Copy link
Copy Markdown
Contributor Author

Thanks!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Reminder: clean up without_legacy_printoptions test decorator TST: 400+ doctest failures because numpy 2.0.dev changed string representation

9 participants