Skip to content

Commit

Permalink
Fixed a bug in ndfilters.generic_filter() where an error was raised…
Browse files Browse the repository at this point in the history
… if all the elements of `mask` were False. (#20)
  • Loading branch information
byrdie authored Oct 21, 2024
1 parent fc021a1 commit 847bc30
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
15 changes: 12 additions & 3 deletions ndfilters/_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,10 @@ def _generic_filter_1d(
values[kx] = array[it, jx]
mask[kx] = where[it, jx]

result[it, ix] = function(values[mask], args)
if np.any(mask):
result[it, ix] = function(values[mask], args)
else:
result[it, ix] = np.nan

return result

Expand Down Expand Up @@ -261,7 +264,10 @@ def _generic_filter_2d(
values = values.reshape(-1)
mask = mask.reshape(-1)

result[it, ix, iy] = function(values[mask], args)
if np.any(mask):
result[it, ix, iy] = function(values[mask], args)
else:
result[it, ix, iy] = np.nan

return result

Expand Down Expand Up @@ -338,6 +344,9 @@ def _generic_filter_3d(
values = values.reshape(-1)
mask = mask.reshape(-1)

result[it, ix, iy, iz] = function(values[mask], args)
if np.any(mask):
result[it, ix, iy, iz] = function(values[mask], args)
else:
result[it, ix, iy, iz] = np.nan

return result
2 changes: 0 additions & 2 deletions ndfilters/_trimmed_mean.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,6 @@ def _trimmed_mean(
(proportion,) = args

nobs = array.size
if nobs == 0:
return np.nan
lowercut = int(proportion * nobs)
uppercut = nobs - lowercut
if lowercut > uppercut: # pragma: nocover
Expand Down

0 comments on commit 847bc30

Please sign in to comment.