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

ENH: ndimage.uniform_filter: implement nan_policy #17393

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

kwodzicki
Copy link

Earlier commit (1871349) implemented ignoring of NaNs in the uniform_filter and uniform_filter1d functions. This commit moves to using the nan_policy keyword argument for determining how NaNs are to be handled so that API calls are consistent across scipy.

Have created a new C-level function that checks/ignores NaN values when computing boxcar averages for the uniform_filter function. This new function is almost identical to the original, but now checks/ignores NaN values when summing and adjusts the number of values in the average based on finite values; i.e., a numpy.nanmean()-like average is taken over the window.

Tests have been added to the testing suite to check that NaN ignoring is working correctly.

A new benchmark has been added to the benchmarking suite; tests indicate very minimal impacts to performance when using ignore_nan=True as opposted to ignore_nan=False. More robust benchmarking should be performed to fully understand any preformance impacts; however, getting the 'right' answer (i.e., not propogating NaNs through entire dataset) is typically more important than being blazing fast.

Closes #7818

Reference issue

What does this implement/fix?

Additional information

Kyle R. Wodzicki added 3 commits November 10, 2022 12:43
Have created a new C-level function that checks/ignores NaN values
when computing boxcar averages for the uniform_filter function.
This new function is almost identical to the original, but now
checks/ignores NaN values when summing and adjusts the number of
values in the average based on finite values; i.e., a
numpy.nanmean()-like average is taken over the window.

At the python level, an 'ignore_nan' keyword has been added to
both the uniform_filter and uniform_filter1d functions. By
default, the original behavior is maintained (i.e., ignore_nan=False)
and no performance penalty is incurred on existing code.

Tests have been added to the testing suite to check that NaN
ignoring is working correctly.

A new benchmark has been added to the benchmarking suite; tests
indicate very minimal impacts to performance when using
ignore_nan=True as opposted to ignore_nan=False. More robust
benchmarking should be performed to fully understand any
preformance impacts; however, getting the 'right' answer
(i.e., not propogating NaNs through entire dataset) is typically
more important than being blazing fast.

See scipy#7818
Earlier commit implemented ignoring of NaNs in the
uniform_filter and uniform_filter1d functions. This commit
moves to using the nan_policy keyword argument for determining
how NaNs are to be handled so that API calls are consistent
across scipy.

Closes scipy#7818
@j-bowhay j-bowhay added enhancement A new feature or improvement scipy.signal labels Nov 10, 2022
@lucascolley lucascolley added the C/C++ Items related to the internal C/C++ code base label Dec 22, 2023
@Jeitan
Copy link

Jeitan commented Jan 26, 2024

Ooo! I somehow only just noticed this. I haven't tested it, but having this would be lovely.

@lucascolley lucascolley changed the title ENH: Implements nan_policy for uniform_filter ENH: Implements nan_policy for uniform_filter Jun 2, 2024
@lucascolley lucascolley changed the title ENH: Implements nan_policy for uniform_filter ENH: ndimage.uniform_filter: implement nan_policy Jun 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C/C++ Items related to the internal C/C++ code base enhancement A new feature or improvement scipy.ndimage
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ndimage uniform_filter expands NaNs all the way to the edge of the array
5 participants