Skip to content

Commit

Permalink
Merge branch 'sdh-approved-filter-fix' into 'main'
Browse files Browse the repository at this point in the history
Update filtering of approved data to search for any match

Closes #91

See merge request water/computational-tools/surface-water-work/hyswap!74
  • Loading branch information
Scott Hamshaw committed Apr 15, 2024
2 parents 831c6cc + 8beb8e3 commit f8dded9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
4 changes: 1 addition & 3 deletions hyswap/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ def filter_approved_data(data, filter_column=None):
"""
if filter_column is None:
raise ValueError("filter_column must be specified.")
return data.loc[((data[filter_column] == "A") |
(data[filter_column] == "A, e") |
(data[filter_column] == "A, R"))]
return data[data[filter_column].str.contains("A")]


def rolling_average(df, data_column_name, data_type,
Expand Down
5 changes: 3 additions & 2 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
class TestDataFilters:
def test_filter_approved_data(self):
"""Test the filter_approved_data function."""
data = {"a": ["A", "A", "P", "P"], "b": [1, 2, 3, 4]}
data = {"a": ["A", "A, e", "A, R", "A, [4]", "P", "P"],
"b": [1, 2, 3, 4, 5, 6]}
data_df = pd.DataFrame(data)
df = utils.filter_approved_data(data_df, filter_column="a")
assert df["b"].tolist() == [1, 2]
assert df["b"].tolist() == [1, 2, 3, 4]

def test_filter_approved_data_error(self):
"""Test the filter_approved_data function."""
Expand Down

0 comments on commit f8dded9

Please sign in to comment.