Skip to content

Convolution: treat infs as nans - #18364

Open
keflavich wants to merge 8 commits into
astropy:mainfrom
keflavich:issue8099
Open

keflavich wants to merge 8 commits into
astropy:mainfrom
keflavich:issue8099

Conversation

@keflavich

Copy link
Copy Markdown
Contributor

Resolves #8099.

convolve_fft has always treated inf as nan, since it is not possible to do otherwise and get a usable result.

convolve has allowed infs to be propagated around by the kernel size.

from astropy.convolution import convolve, convolve_fft, Gaussian1DKernel
ar = np.ones(10)
ar[5] = np.inf
gaussian = Gaussian1DKernel(1, x_size=5)
convolve_fft(ar, gaussian)
 # array([0.70130997, 0.94551132, 1.        , 1.        , 1.        ,
 #      1.        , 1.        , 1.        , 0.94551132, 0.70130997])
convolve(ar, gaussian)
 # array([0.70130997, 0.94551132, 1.        ,        inf,        inf,
 #             inf,        inf,        inf, 0.94551132, 0.70130997])

This PR prevents the latter behavior. I think it is a correct solution, but it is theoretically possible that someone has relied on this 'bug' over the last 7 years, so it warrants allowing for some minimal discussion.

@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 instructions for rebase and squash.
  • 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?
  • 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 added this to the v7.2.0 milestone Jun 30, 2025
@astrofrog astrofrog modified the milestones: v7.2.0, v9.0.0, v8.0.0 Nov 3, 2025
@github-actions github-actions Bot added the Close? Tell stale bot that this issue/PR is stale label Nov 26, 2025
@github-actions

Copy link
Copy Markdown
Contributor

Hi humans 👋 - this pull request hasn't had any new commits for approximately 4 months. I plan to close this in 30 days if the pull request doesn't have any new commits by then.

In lieu of a stalled pull request, please consider closing this and open an issue instead if a reminder is needed to revisit in the future. Maintainers may also choose to add keep-open label to keep this PR open but it is discouraged unless absolutely necessary.

If this PR still needs to be reviewed, as an author, you can rebase it to reset the clock.

If you believe I commented on this pull request incorrectly, please report this here.

@keflavich keflavich removed the Close? Tell stale bot that this issue/PR is stale label Nov 28, 2025
@keflavich

Copy link
Copy Markdown
Contributor Author

I used an LLM to write the tests, but I checked the numerical values by hand (they got them wrong sometimes anyway... unfortunately my by-hand checking is not guaranteed to be correct at only 0.75 coffees into the day).

TODO: Why is the coverage <100%?

@pllim

pllim commented Nov 28, 2025

Copy link
Copy Markdown
Member

Why is the coverage <100%?

The report in Details might give you clue. A rebase might also help (but maybe not but doesn't hurt).

@keflavich

Copy link
Copy Markdown
Contributor Author

thanks. i thought i had rebased already, but maybe i lost this one in the mix...

@pllim

pllim commented Nov 28, 2025

Copy link
Copy Markdown
Member

Well, I am just conveying that GH is telling me. 😅

Screenshot 2025-11-28 125848

@keflavich

Copy link
Copy Markdown
Contributor Author

I had rebased, but apparently hadn't fetched recently enough.

@keflavich
keflavich marked this pull request as ready for review November 28, 2025 18:18
@pllim

pllim commented Nov 28, 2025

Copy link
Copy Markdown
Member

Still need that change log fragment. Thanks!

@github-actions github-actions Bot added the Close? Tell stale bot that this issue/PR is stale label Apr 28, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Hi humans 👋 - this pull request hasn't had any new commits for approximately 4 months. I plan to close this in 30 days if the pull request doesn't have any new commits by then.

In lieu of a stalled pull request, please consider closing this and open an issue instead if a reminder is needed to revisit in the future. Maintainers may also choose to add keep-open label to keep this PR open but it is discouraged unless absolutely necessary.

If this PR still needs to be reviewed, as an author, you can rebase it to reset the clock.

If you believe I commented on this pull request incorrectly, please report this here.

@keflavich keflavich added keep-open and removed Close? Tell stale bot that this issue/PR is stale labels Apr 28, 2026

@larrybradley larrybradley 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, @keflavich. I have a few comments to address.

As a general comment (not for this PR), we should eventually clean up the tests to parameterize convolve/convolve_fft. There is a lot of duplicated test code.

Also, this PR has merge conflicts and needs a rebase.

convolve_fft should treat infinities like NaN values.
Regression test for issue #8099.
"""
from astropy.convolution import Gaussian1DKernel

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.

Move import to top of file.

Comment thread astropy/convolution/convolve.py Resolved
Comment thread docs/changes/convolution/18364.api.rst Resolved
Comment thread astropy/convolution/convolve.py Resolved
Comment thread astropy/convolution/convolve.py Resolved
assert not np.any(np.isnan(result))


def test_convolve_fft_kernel_with_inf():

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.

This test is identical to test_kernel_with_inf. Remove one of them.

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.

I bet this was from a bad rebase way back months ago...

@larrybradley

Copy link
Copy Markdown
Member

pre-commit.ci autofix

@larrybradley

Copy link
Copy Markdown
Member

@keflavich This PR stills need a rebase to resolve merge conflicts.

@astrofrog astrofrog modified the milestones: v8.0.0, v8.1.0 May 5, 2026
@pllim pllim removed the keep-open label Oct 14, 2026
@github-actions github-actions Bot added the Close? Tell stale bot that this issue/PR is stale label Oct 15, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Hi humans 👋 - this pull request hasn't had any new commits for approximately 6 months. I plan to close this in a month if the pull request doesn't have any new commits by then.

In lieu of a stalled pull request, please consider closing this and open an issue instead if a reminder is needed to revisit in the future. Maintainers may also choose to add keep-open label to keep this PR open but it is discouraged unless absolutely necessary.

If this PR still needs to be reviewed, as an author, you can rebase it to reset the clock.

If you believe I commented on this pull request incorrectly, please report this here.

This branch has not been deployed

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

Labels

Close? Tell stale bot that this issue/PR is stale convolution

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Convolution: should NaN interpolation inc. inf?

4 participants