Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix divide_by_even_rate bug #61

Merged
merged 1 commit into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading