in core/maxframe/dataframe/reduction/aggregation.py [0:0]
def normalize_reduction_funcs(op, ndim=None):
raw_func = op.raw_func
if ndim == 1 and raw_func is None:
raw_func = op.raw_func_kw
if raw_func is not None:
if isinstance(raw_func, dict):
if ndim == 2:
new_func = OrderedDict()
for k, v in raw_func.items():
if isinstance(v, str) or callable(v):
new_func[k] = [v]
else:
new_func[k] = v
op.func = new_func
else:
op.func = list(raw_func.values())
op.func_rename = list(raw_func.keys())
elif isinstance(raw_func, Iterable) and not isinstance(raw_func, str):
op.func = list(raw_func)
else:
op.func = [raw_func]
else:
new_func = OrderedDict()
new_func_names = OrderedDict()
for k, v in op.raw_func_kw.items():
try:
col_funcs = new_func[v[0]]
col_func_names = new_func_names[v[0]]
except KeyError:
col_funcs = new_func[v[0]] = []
col_func_names = new_func_names[v[0]] = []
col_funcs.append(v[1])
col_func_names.append(k)
op.func = new_func
op.func_rename = functools.reduce(
lambda a, b: a + b, new_func_names.values(), []
)
custom_idx = 0
if isinstance(op.func, list):
custom_iter = (f for f in op.func if isinstance(f, CustomReduction))
else:
custom_iter = (f for f in op.func.values() if isinstance(f, CustomReduction))
for r in custom_iter:
if r.name == "<custom>":
r.name = f"<custom_{custom_idx}>"
custom_idx += 1