-
Notifications
You must be signed in to change notification settings - Fork 24
test coverage for filters #229
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
Merged
tennlee
merged 26 commits into
ACCESS-Community-Hub:develop
from
edoyango:xarray_remapping_tests
Dec 17, 2025
Merged
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
d732fcb
make healpix importable
edoyango 2b33bb6
add no healpy import test
edoyango a53a6ff
ensure fallback HEALPix works with args
edoyango 6ad4f7b
test numpy dropvalue
edoyango a9cc8ad
add missing brackets
edoyango 81ced15
cover numpy filters
edoyango 8d7954c
_check -> filter
edoyango 19e45d0
remove not
edoyango 89b9f2e
add dataarray capability to DropAnyNan
edoyango 8ccbb12
add test for xarray dropanynan filter
edoyango a9e9ada
add check for invalid types
edoyango 52d6645
add dataarray capability for dropallnan
edoyango 5c796b1
add tests for dropallnan
edoyango 2e49922
add dataset functionality for dropvalue
edoyango eae59f7
add tests for dropvalue
edoyango e95439c
add coverage for Shape
edoyango 01d9ade
remove not in DropAnyNan and DropAllNan
edoyango 21b5ac1
check_shape -> filter
edoyango 7813538
fix mismatched tuple length error
edoyango 0b43a9f
add dask filter tests
edoyango e8113ff
Remove unused import
tennlee ad2e679
Simplify CI/CD install requirements to bring install under disk space…
tennlee e37f4e2
Test reduced dependencies
tennlee 08c84df
Test reduced-complexity requirements installation for CI/CD needs
tennlee 147e3c8
Test further reduction of dependencies for CI/CD
tennlee 1c57155
Test tweak
tennlee File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
packages/pipeline/tests/operations/dask/test_dask_filter.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| # Copyright Commonwealth of Australia, Bureau of Meteorology 2025. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| from pyearthtools.pipeline.operations.dask import filters | ||
| from pyearthtools.pipeline.exceptions import PipelineFilterException | ||
|
|
||
| import numpy as np | ||
| import dask.array as da | ||
| import pytest | ||
|
|
||
|
|
||
| def test_DropAnyNan(): | ||
| """Tests DropAnyNan dask filter.""" | ||
|
|
||
| original = da.ones((2, 2)) | ||
|
|
||
| # no nans - should succeed quietly | ||
| drop = filters.DropAnyNan() | ||
| drop.filter(original) | ||
|
|
||
| # one nan - should raise exception | ||
| original[0, 0] = np.nan | ||
| drop = filters.DropAnyNan() | ||
| with pytest.raises(PipelineFilterException): | ||
| drop.filter(original) | ||
|
|
||
|
|
||
| # xfailed since the result seems to be inverted to documented requirements | ||
| @pytest.mark.xfail | ||
| def test_DropAllNan(): | ||
| """Tests DropAllNan dask filter.""" | ||
|
|
||
| original = da.empty((2, 2)) | ||
|
|
||
| # no nans - should succeed quietly | ||
| drop = filters.DropAllNan() | ||
| drop.filter(original) | ||
|
|
||
| # one nan - should succeed quietly | ||
| original[0, 0] = np.nan | ||
| drop.filter(original) | ||
|
|
||
| # all nans - should raise exception | ||
| original[:, :] = np.nan | ||
| with pytest.raises(PipelineFilterException): | ||
| drop.filter(original) | ||
|
|
||
|
|
||
| def test_DropValue(): | ||
| """Tests DropValue dask filter.""" | ||
|
|
||
| original = da.from_array([[0, 0], [1, 2]]) | ||
|
|
||
| # drop case (num zeros < threshold) | ||
| drop = filters.DropValue(0, 75) | ||
| with pytest.raises(PipelineFilterException): | ||
| drop.filter(original) | ||
|
|
||
| # non-drop case (num zeros >= threshold) | ||
| drop = filters.DropValue(0, 50) | ||
| drop.filter(original) | ||
|
|
||
| # drop case (num nans < threshold) | ||
| original = da.from_array([[np.nan, np.nan], [1, 2]]) | ||
| drop = filters.DropValue("nan", 75) | ||
| with pytest.raises(PipelineFilterException): | ||
| drop.filter(original) | ||
|
|
||
| # non-drop case (num nans >= threshold) | ||
| drop = filters.DropValue("nan", 50) | ||
| drop.filter(original) | ||
|
|
||
|
|
||
| def test_Shape(): | ||
| """Tests Shape dask filter.""" | ||
|
|
||
| originals = (da.empty((2, 2)), da.empty((2, 3))) | ||
|
|
||
| # check drop case | ||
| drop = filters.Shape((2, 3)) | ||
| with pytest.raises(PipelineFilterException): | ||
| drop.filter(originals[0]) | ||
|
|
||
| # check non-drop case | ||
| drop = filters.Shape((2, 2)) | ||
| drop.filter(originals[0]) | ||
|
|
||
| # check tuple inputs drop cases | ||
| drop = filters.Shape(((2, 3), (2, 3))) | ||
| with pytest.raises(PipelineFilterException): | ||
| drop.filter(originals) | ||
|
|
||
| # check tuple inputs non-drop cases | ||
| drop = filters.Shape(((2, 2), (2, 3))) | ||
| drop.filter(originals) | ||
|
|
||
| # invalid mismatched shape and input | ||
| drop = filters.Shape(((2, 2),)) | ||
| with pytest.raises(RuntimeError): | ||
| drop.filter(originals) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From the doc string for DropValue:
all the DropValue filters calculate whether % of elemns matching value >= the percentage, and then not's them here, which does the opposite of what the doc string says. @tennlee should I follow what the doc string says or leave the logic as is?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The top-level filter class says "
filtershould sairse aPipelineFilterExceptionif invalid. So I think thenotis unwanted? The test for me is that a pipelinefilterexception should be raised if data with a high proportion of nans (or whatever query value) is supplied.