Skip to content

move scipy imports#12192

Merged
nstarman merged 1 commit into
astropy:mainfrom
nstarman:cosmo_move_imports
Sep 24, 2021
Merged

move scipy imports#12192
nstarman merged 1 commit into
astropy:mainfrom
nstarman:cosmo_move_imports

Conversation

@nstarman

@nstarman nstarman commented Sep 23, 2021

Copy link
Copy Markdown
Member

Don't import every time the function is called.

Edit: this is mostly a stylistic change (as the import is fairly inexpensive), but this implementation is better because it separates the logic of optional dependencies from the actual physics.

Signed-off-by: Nathaniel Starkman (@nstarman) nstarkman@protonmail.com

Checklist for package maintainer(s)

This checklist is meant to remind the package maintainer(s) who will review this pull request of some common things to look for. This list is not exhaustive.

  • 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.
  • 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 a milestone set? Milestone must be set but astropy-bot check might be missing; 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.

@dhomeier dhomeier left a comment

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.

LGTM; could probably need some explanation on the motivation of these changes in the description, but AFAICT does what it is supposed to do.

Comment thread astropy/cosmology/tests/test_flrw.py Outdated
Comment thread astropy/cosmology/tests/test_flrw.py Outdated
##############################################################################


@pytest.mark.skipif(HAS_SCIPY, reason="can't have :mod:`scipy` imported")

@pllim pllim Sep 24, 2021

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.

No need to be too fancy with the reason here. It doesn't even show up in the test log and definitely will not be rendered by anything user facing. It is just a note for devs.

Suggested change
@pytest.mark.skipif(HAS_SCIPY, reason="can't have :mod:`scipy` imported")
@pytest.mark.skipif(HAS_SCIPY, reason="scipy is installed")

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.

Yes, just at very first reading it did not make much sense to me.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

SGTM.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

On a related note, this test doesn't seem to be running! I don't see any reason why it doesn't run (except when scipy is installed)!

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.

You mean, it doesn't run in CI or locally? Check the pytest header. Maybe somehow all our jobs pull in scipy.

@nstarman nstarman Sep 24, 2021

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Ohh! We should fix that. Codecov can merge the coverage reports.
Followup PR?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Add coverage to Python 3.9 with minimal dependencies?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

change it to

          - name: Python 3.9 with minimal dependencies and full coverage
            os: ubuntu-latest
            python: 3.9
            toxenv: py39-test-cov-clocale

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.

Yes, let's explore that as a separate PR. 😸

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.

Yes, testing both minimal and full dependencies sounds sensible.
Wondering how is this going to be evaluated, e.g. if one job reports increased and the other decreased coverage... 👻

Signed-off-by: Nathaniel Starkman (@nstarman) <nstarkman@protonmail.com>
@nstarman nstarman merged commit 424293f into astropy:main Sep 24, 2021
@nstarman nstarman deleted the cosmo_move_imports branch September 24, 2021 21:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants