-
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
1 parent
89bcc83
commit e51a04e
Showing
2 changed files
with
39 additions
and
1 deletion.
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import pandas as pd | ||
import pytest | ||
|
||
from acbm.assigning import _map_day_to_wkday_binary | ||
|
||
# applying to a single value | ||
|
||
|
||
@pytest.mark.parametrize( | ||
("day", "expected"), [(1, 1), (2, 1), (3, 1), (4, 1), (5, 1), (6, 0), (7, 0)] | ||
) | ||
def test_map_day_to_wkday_binary_valid(day, expected): | ||
assert _map_day_to_wkday_binary(day) == expected | ||
|
||
|
||
def test_map_day_to_wkday_binary_invalid(): | ||
with pytest.raises(ValueError, match="Day should be numeric and in the range 1-7"): | ||
_map_day_to_wkday_binary(8) | ||
|
||
|
||
# applying to a df | ||
|
||
|
||
def test_map_day_to_wkday_binary_df(): | ||
df = pd.DataFrame({"day": [1, 2, 3, 4, 5, 6, 7]}) | ||
df["wkday"] = df["day"].apply(_map_day_to_wkday_binary) | ||
assert df["wkday"].tolist() == [1, 1, 1, 1, 1, 0, 0] | ||
|
||
|
||
# test applying the function to a df column with an invalid value | ||
def test_map_day_to_wkday_binary_df_invalid(): | ||
df = pd.DataFrame({"day": [1, 2, 3, 4, 5, 6, 7, 8]}) | ||
with pytest.raises(ValueError, match="Day should be numeric and in the range 1-7"): | ||
df["wkday"] = df["day"].apply(_map_day_to_wkday_binary) |