Skip to content

Commit dcbf1e4

Browse files
author
samuel.oranyeli
committed
remove checks from dict
1 parent 3602166 commit dcbf1e4

File tree

2 files changed

+6
-19
lines changed

2 files changed

+6
-19
lines changed

janitor/functions/summarize.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -109,14 +109,7 @@ def summarize(
109109

110110
for num, arg in enumerate(args):
111111
check(f"Argument {num} in the summarize function", arg, [dict, tuple])
112-
if isinstance(arg, dict):
113-
for col, func in arg.items():
114-
check(
115-
f"func for {col} in argument {num}",
116-
func,
117-
[str, callable],
118-
)
119-
else:
112+
if isinstance(arg, tuple):
120113
if len(arg) < 2:
121114
raise ValueError(
122115
f"Argument {num} should have a minimum length of 2, "
@@ -164,6 +157,9 @@ def summarize(
164157
val = grp if by_is_true else df
165158
if isinstance(func, str):
166159
val = val[col]
160+
elif is_scalar(func):
161+
aggs[col] = func
162+
break
167163
try:
168164
outcome = val.agg(func)
169165
except (ValueError, AttributeError):

tests/functions/test_summarize.py

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,6 @@ def test_dict_args_error(dataframe):
1515
dataframe.summarize(1)
1616

1717

18-
@pytest.mark.functions
19-
def test_dict_args_val_error(dataframe):
20-
"""
21-
Raise if arg is a dict,
22-
key exist in the columns,
23-
but the value is not a string or callable
24-
"""
25-
with pytest.raises(TypeError, match="func for a in argument 0.+"):
26-
dataframe.summarize({"a": 1})
27-
28-
2918
func = lambda grp: grp.Revenue.sum() / grp.Quantity.sum() # noqa: E731
3019

3120

@@ -95,6 +84,8 @@ def test_tuple_func_seq_error(dataframe):
9584

9685

9786
args = [
87+
{"a": "sum"},
88+
{"a": pd.Series([1, 2, 3] * 3).sum()},
9889
{"a": lambda df: df.a.sum()},
9990
("a", "sum"),
10091
("a", np.sum),

0 commit comments

Comments
 (0)