def test_maybe_mangle_lambdas_listlike(): aggfuncs = [lambda x: 1, lambda x: 2] result = maybe_mangle_lambdas(aggfuncs) assert result[0].__name__ == "<lambda_0>" assert result[1].__name__ == "<lambda_1>" assert aggfuncs[0](None) == result[0](None) assert aggfuncs[1](None) == result[1](None)
def test_maybe_mangle_lambdas_args(): func = {"A": [lambda x, a, b=1: (0, a, b), lambda x: 1]} result = maybe_mangle_lambdas(func) assert result["A"][0].__name__ == "<lambda_0>" assert result["A"][1].__name__ == "<lambda_1>" assert func["A"][0](0, 1) == (0, 1, 1) assert func["A"][0](0, 1, 2) == (0, 1, 2) assert func["A"][0](0, 2, b=3) == (0, 2, 3)
def test_maybe_mangle_lambdas_passthrough(): assert maybe_mangle_lambdas("mean") == "mean" assert maybe_mangle_lambdas(lambda x: x).__name__ == "<lambda>" # don't mangel single lambda. assert maybe_mangle_lambdas([lambda x: x])[0].__name__ == "<lambda>"
def test_maybe_mangle_lambdas_named(): func = {"C": np.mean, "D": {"foo": np.mean, "bar": np.mean}} result = maybe_mangle_lambdas(func) assert result == func
def test_maybe_mangle_lambdas(): func = {"A": [lambda x: 0, lambda x: 1]} result = maybe_mangle_lambdas(func) assert result["A"][0].__name__ == "<lambda_0>" assert result["A"][1].__name__ == "<lambda_1>"