Skip to content

Commit

Permalink
add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
samuel.oranyeli committed Feb 1, 2023
1 parent 31f615b commit 4fad0d6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
2 changes: 1 addition & 1 deletion janitor/functions/summarize.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def summarize(
grp = df.groupby(**by)
elif by_is_true and isinstance(by, col):
if by.func:
raise ValueError("Function assignment is not required within by.")
raise ValueError("Function assignment is not required within by")
cols = get_index_labels([*by.cols], df, axis="columns")
if by.remove_cols:
exclude = get_index_labels([*by.remove_cols], df, axis="columns")
Expand Down
20 changes: 18 additions & 2 deletions tests/functions/test_summarize.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import pandas as pd

from pandas.testing import assert_frame_equal
from pandas.api.types import is_numeric_dtype
from pandas.api.types import is_numeric_dtype, is_string_dtype
from janitor import col


Expand All @@ -19,6 +19,20 @@ def test_Column_agg_error(dataframe):
dataframe.summarize(col("a").compute(func))


@pytest.mark.functions
def test_Column_by_error(dataframe):
"""
Raise if `by` is a col class, and has a function
assigned to it
"""
with pytest.raises(
ValueError, match="Function assignment is not required within by"
):
dataframe.summarize(
col("a").compute("sum"), by=col("b").compute("size")
)


@pytest.mark.functions
def test_Column_exclude_error(dataframe):
"""
Expand Down Expand Up @@ -210,5 +224,7 @@ def test_dataframe():

df = pd.DataFrame(df)
expected = df.groupby("A").C.describe().add_prefix("C_")
actual = df.summarize(col("C").compute("describe"), by="A")
actual = df.summarize(
col("C").compute("describe"), by=col(is_string_dtype).exclude("B")
)
assert_frame_equal(expected, actual)

0 comments on commit 4fad0d6

Please sign in to comment.