Skip to content

Avoid importing astropy.stats for astropy.modeling#7936

Merged
mhvk merged 2 commits into
astropy:masterfrom
astrofrog:avoid-stats-import
Oct 21, 2018
Merged

Avoid importing astropy.stats for astropy.modeling#7936
mhvk merged 2 commits into
astropy:masterfrom
astrofrog:avoid-stats-import

Conversation

@astrofrog

Copy link
Copy Markdown
Member

This removes the only import of astropy.stats in astropy.modeling, which speeds up the import of astropy.modeling from ~1.8 seconds to ~1.5 seconds on my machine (as profiled with -X importtime). I noticed this while debugging an issue in astropy-benchmarks which is caused by importing astropy.modeling ultimately importing pytest. This doesn't fix the root cause (see #7932 for that) but avoids a long chain of imports that isn't needed.

@astropy-bot

astropy-bot Bot commented Oct 20, 2018

Copy link
Copy Markdown

Hi there @astrofrog 👋 - thanks for the pull request! I'm just a friendly 🤖 that checks for issues related to the changelog and making sure that this pull request is milestoned and labeled correctly. This is mainly intended for the maintainers, so if you are not a maintainer you can ignore this, and a maintainer will let you know if any action is required on your part 😃.

Everything looks good from my point of view! 👍

If there are any issues with this message, please report them here.

@astrofrog astrofrog added this to the v3.1 milestone Oct 20, 2018

@mhvk mhvk 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.

This makes sense, but just to ensure things stay consistent, maybe add a test? Or am I overly paranoid??

@astrofrog

Copy link
Copy Markdown
Member Author

@mhvk - you mean to check the value of GAUSSIAN_SIGMA_TO_FWHM is the same in both modules?

@mhvk

mhvk commented Oct 20, 2018

Copy link
Copy Markdown
Contributor

Yes, that's what I meant. Really shouldn't change, of course...

@astrofrog

Copy link
Copy Markdown
Member Author

@mhvk - added!

@mhvk mhvk 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.

All OK.

@mhvk mhvk merged commit d5a6ac1 into astropy:master Oct 21, 2018
# Note that we define this here rather than using the value defined in
# astropy.stats to avoid importing astropy.stats every time astropy.modeling
# is loaded.
GAUSSIAN_SIGMA_TO_FWHM = 2.0 * np.sqrt(2.0 * np.log(2.0))

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.

Doesn't quite sit well with my OCD to have the same thing defined in multiple places. Is it possible to move this to constants or does that also introduce import time penalty? Anyways, just a thought.

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.

Practicality beats purity

@astrofrog astrofrog deleted the avoid-stats-import branch November 14, 2018 15:23
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.

3 participants