-
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
2 changed files
with
35 additions
and
35 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 |
---|---|---|
@@ -1,34 +1,37 @@ | ||
from src.predictive_variable import shift_by_strata_period | ||
from pathlib import Path | ||
|
||
import pytest | ||
from helper_functions import load_and_format | ||
from pandas.testing import assert_frame_equal | ||
|
||
import pytest | ||
from src.predictive_variable import shift_by_strata_period | ||
|
||
|
||
@pytest.fixture(scope="class") | ||
def predictive_variable_test_data(): | ||
return load_and_format(Path("tests") / "predictive_variable.csv") | ||
|
||
|
||
class TestPredictiveVariable: | ||
def test_predictive_variable_forward(self, predictive_variable_test_data): | ||
expected_output = predictive_variable_test_data[ | ||
['identifier', 'period', 'group', 'question', 'other',"f_predictive" | ||
]] | ||
["identifier", "period", "group", "question", "other", "f_predictive"] | ||
] | ||
input_data = expected_output.drop(columns="f_predictive") | ||
actual_output = shift_by_strata_period( | ||
input_data, "question", "period", "group","identifier",1,"f_predictive" | ||
input_data, "question", "period", "group", "identifier", 1, "f_predictive" | ||
) | ||
actual_output.sort_index(ascending=True,inplace=True) | ||
actual_output.sort_index(ascending=True, inplace=True) | ||
assert_frame_equal(actual_output, expected_output) | ||
|
||
def test_predictive_variable_backward(self, predictive_variable_test_data): | ||
|
||
expected_output = predictive_variable_test_data[ | ||
['identifier', 'period', 'group', 'question', 'other',"b_predictive" | ||
]] | ||
["identifier", "period", "group", "question", "other", "b_predictive"] | ||
] | ||
input_data = expected_output.drop(columns="b_predictive") | ||
actual_output = shift_by_strata_period( | ||
input_data, "question", "period", "group","identifier",-1,"b_predictive" | ||
input_data, "question", "period", "group", "identifier", -1, "b_predictive" | ||
) | ||
actual_output.sort_index(ascending=True,inplace=True) | ||
assert_frame_equal(actual_output, expected_output) | ||
actual_output.sort_index(ascending=True, inplace=True) | ||
assert_frame_equal(actual_output, expected_output) |