Skip to content

Commit 614821d

Browse files
author
samuel.oranyeli
committed
separate string function calls
1 parent dcbf1e4 commit 614821d

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

janitor/functions/summarize.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -156,14 +156,14 @@ def summarize(
156156
for col, func in arg.items():
157157
val = grp if by_is_true else df
158158
if isinstance(func, str):
159-
val = val[col]
159+
outcome = val[col].agg(func)
160160
elif is_scalar(func):
161-
aggs[col] = func
162-
break
163-
try:
164-
outcome = val.agg(func)
165-
except (ValueError, AttributeError):
166-
outcome = func(val)
161+
outcome = func
162+
else:
163+
try:
164+
outcome = val.agg(func)
165+
except (ValueError, AttributeError):
166+
outcome = func(val)
167167
aggs[col] = outcome
168168
else:
169169
columns, func, names = SD(*arg)
@@ -205,10 +205,13 @@ def summarize(
205205
name = f"{col}{name}"
206206
else:
207207
name = col
208-
try:
208+
if isinstance(funcn, str):
209209
outcome = val.agg(funcn)
210-
except (ValueError, AttributeError):
211-
outcome = funcn(val)
210+
else:
211+
try:
212+
outcome = val.agg(funcn)
213+
except (ValueError, AttributeError):
214+
outcome = funcn(val)
212215
aggs[name] = outcome
213216
aggs = {
214217
col: [outcome] if is_scalar(outcome) else outcome

0 commit comments

Comments
 (0)