-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
68 additions
and
46 deletions.
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
|
@@ -2,4 +2,4 @@ group,period,flag_1,flag_2 | |
1,202401,1,0 | ||
1,202402,0,2 | ||
2,202401,2,1 | ||
2,202402,1,1 | ||
2,202402,1,1 |
This file contains 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 |
---|---|---|
|
@@ -6,4 +6,4 @@ period,group,flag_1,flag_2 | |
202401,2,1,TRUE | ||
202401,2,1,FALSE | ||
202402,2,0,FALSE | ||
202402,2,1,TRUE | ||
202402,2,1,TRUE |
This file contains 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 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 |
---|---|---|
@@ -1,38 +1,53 @@ | ||
import pandas as pd | ||
import pytest | ||
|
||
from pandas.testing import assert_frame_equal | ||
from pathlib import Path | ||
|
||
from src.flag_and_count_matched_pairs import flag_matched_pair, count_matches | ||
import pandas as pd # noqa F401 | ||
import pytest | ||
from helper_functions import load_and_format | ||
from pandas.testing import assert_frame_equal | ||
|
||
from src.flag_and_count_matched_pairs import count_matches, flag_matched_pair | ||
|
||
|
||
@pytest.fixture(scope="class") | ||
def match_test_data(): | ||
return load_and_format(Path('tests')/'test_data_matched_pair/flag_pairs_expected_output.csv') | ||
return load_and_format( | ||
Path("tests") / "test_data_matched_pair/flag_pairs_expected_output.csv" | ||
) | ||
|
||
|
||
@pytest.fixture(scope="class") | ||
def count_test_data(): | ||
return load_and_format(Path('tests')/'test_data_matched_pair/count_matches_input.csv') | ||
|
||
return load_and_format( | ||
Path("tests") / "test_data_matched_pair/count_matches_input.csv" | ||
) | ||
|
||
|
||
@pytest.fixture(scope="class") | ||
def count_expected_output(): | ||
return load_and_format(Path('tests')/'test_data_matched_pair/count_matches_expected_output.csv') | ||
return load_and_format( | ||
Path("tests") / "test_data_matched_pair/count_matches_expected_output.csv" | ||
) | ||
|
||
|
||
class TestMatchedPair: | ||
def test_flag_matched_pair_forward(self, match_test_data): | ||
expected_output = match_test_data.drop(['b_match'],axis = 1) | ||
df_input = match_test_data[['reference', 'strata', 'period', 'target_variable']] | ||
df_output = flag_matched_pair(df_input,'f','target_variable','period', 'reference', 'strata') | ||
assert_frame_equal(df_output, expected_output) | ||
|
||
def test_flag_matched_pair_backward(self, match_test_data): | ||
expected_output = match_test_data.drop(['f_match'],axis = 1) | ||
df_input = match_test_data[['reference', 'strata', 'period', 'target_variable']] | ||
df_output = flag_matched_pair(df_input,'b','target_variable','period', 'reference', 'strata') | ||
assert_frame_equal(df_output, expected_output) | ||
|
||
def test_flag_matched_pair_forward(self, match_test_data): | ||
expected_output = match_test_data.drop(["b_match"], axis=1) | ||
df_input = match_test_data[["reference", "strata", "period", "target_variable"]] | ||
df_output = flag_matched_pair( | ||
df_input, "f", "target_variable", "period", "reference", "strata" | ||
) | ||
assert_frame_equal(df_output, expected_output) | ||
|
||
def test_flag_matched_pair_backward(self, match_test_data): | ||
expected_output = match_test_data.drop(["f_match"], axis=1) | ||
df_input = match_test_data[["reference", "strata", "period", "target_variable"]] | ||
df_output = flag_matched_pair( | ||
df_input, "b", "target_variable", "period", "reference", "strata" | ||
) | ||
assert_frame_equal(df_output, expected_output) | ||
|
||
|
||
class TestCountMatches: | ||
def test_count_matches(self, count_test_data, count_expected_output): | ||
output = count_matches(count_test_data, ["flag_1", "flag_2"], "period", "group") | ||
assert_frame_equal(output, count_expected_output) | ||
def test_count_matches(self, count_test_data, count_expected_output): | ||
output = count_matches(count_test_data, ["flag_1", "flag_2"], "period", "group") | ||
assert_frame_equal(output, count_expected_output) |