Skip to content

Commit

Permalink
use dataclass instead of namedtuple
Browse files Browse the repository at this point in the history
  • Loading branch information
samukweku committed Jan 12, 2023
1 parent d38a0ad commit 31debc3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
11 changes: 7 additions & 4 deletions janitor/functions/summarize.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ def summarize(
f"Argument {num} should have a maximum length of 3, "
f"instead got {len(arg)}"
)
_, func, names = SD(*arg)
data = SD(*arg)
func = data.func
check(
f"The function (position 1 in the tuple) for argument {num} ",
func,
Expand All @@ -151,7 +152,7 @@ def summarize(
funcn,
[str, callable],
)

names = data.names_glue
if names:
check(
f"The names (position 2 in the tuple) for argument {num} ",
Expand Down Expand Up @@ -190,9 +191,10 @@ def summarize(
aggs[col] = outcome

else:
columns, func, names = SD(*arg)
columns = _select_index([columns], df, axis="columns")
data = SD(*arg)
columns = _select_index([data.columns], df, axis="columns")
columns = df.columns[columns]
func = data.func
if not isinstance(func, (list, tuple)):
func = [func]
func_names = [
Expand Down Expand Up @@ -220,6 +222,7 @@ def summarize(
func_names = func_list
counts = None
func_names = tuple(zip(func_names, func))
names = data.names_glue
for col in columns:
if by_is_true:
val = grp[col]
Expand Down
4 changes: 2 additions & 2 deletions janitor/functions/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
Union,
Callable,
Any,
NamedTuple,
)
from pandas.core.dtypes.generic import ABCPandasArray, ABCExtensionArray
from pandas.core.common import is_bool_indexer
Expand Down Expand Up @@ -615,7 +614,8 @@ def _convert_to_numpy_array(
return left, right


class SD(NamedTuple):
@dataclass()
class SD:
"""
Subset of Data.
Used in `mutate` and `summarize`
Expand Down

0 comments on commit 31debc3

Please sign in to comment.