Skip to content

Commit

Permalink
test for above and below 1
Browse files Browse the repository at this point in the history
  • Loading branch information
wd60622 committed Apr 16, 2024
1 parent 01b80ac commit 46004e9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
2 changes: 1 addition & 1 deletion latent_calendar/extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ def divide_by_even_rate(self) -> pd.DataFrame:
"""
value = self._obj.shape[1]
return self._obj.div(value)
return self._obj.mul(value)

def normalize(self, kind: Literal["max", "probs", "even_rate"]) -> pd.DataFrame:
"""Row-wise operations on DataFrame.
Expand Down
20 changes: 18 additions & 2 deletions tests/test_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ def test_sum_normalize(df) -> None:
def test_even_rate_normalize(df) -> None:
df_even_rate_result = pd.DataFrame(
{
"a": [1 / 3, 2 / 3, 3 / 3],
"b": [4 / 3, 5 / 3, 6 / 3],
"a": [1 * 3, 2 * 3, 3 * 3],
"b": [4 * 3, 5 * 3, 6 * 3],
}
).T

Expand All @@ -128,6 +128,22 @@ def test_even_rate_normalize(df) -> None:
)


def test_even_rate_probability_distribution(df) -> None:
df_even_rate_result = pd.DataFrame(
{
"a": [0.5, 1.0, 1.5],
"b": [0.8, 1.0, 1.2],
}
).T

df_probs = df.div(df.sum(axis=1), axis=0)

pd.testing.assert_frame_equal(
df_probs.cal.divide_by_even_rate(),
df_even_rate_result,
)


def test_unknown_normalize(df) -> None:
with pytest.warns(DeprecationWarning):
with pytest.raises(ValueError):
Expand Down

0 comments on commit 46004e9

Please sign in to comment.