From f5d2ad970ab5ec3cf16ffaab4c5b5ddc00ff1fa0 Mon Sep 17 00:00:00 2001 From: Christopher Whelan Date: Sat, 5 Jan 2019 06:53:22 -0800 Subject: [PATCH] CLN: replace lambdas with named functions so they are labeled in asv (#24629) --- asv_bench/benchmarks/ctors.py | 52 ++++++++++++++++++++++++++++++----- 1 file changed, 45 insertions(+), 7 deletions(-) diff --git a/asv_bench/benchmarks/ctors.py b/asv_bench/benchmarks/ctors.py index 198ed1c90a2e98..7c78fe7e7a1770 100644 --- a/asv_bench/benchmarks/ctors.py +++ b/asv_bench/benchmarks/ctors.py @@ -3,17 +3,55 @@ from pandas import Series, Index, DatetimeIndex, Timestamp, MultiIndex +def no_change(arr): + return arr + + +def list_of_str(arr): + return list(arr.astype(str)) + + +def gen_of_str(arr): + return (x for x in arr.astype(str)) + + +def arr_dict(arr): + return dict(zip(range(len(arr)), arr)) + + +def list_of_tuples(arr): + return [(i, -i) for i in arr] + + +def gen_of_tuples(arr): + return ((i, -i) for i in arr) + + +def list_of_lists(arr): + return [[i, -i] for i in arr] + + +def list_of_tuples_with_none(arr): + return [(i, -i) for i in arr][:-1] + [None] + + +def list_of_lists_with_none(arr): + return [[i, -i] for i in arr][:-1] + [None] + + class SeriesConstructors(object): param_names = ["data_fmt", "with_index"] - params = [[lambda x: x, + params = [[no_change, list, - lambda arr: list(arr.astype(str)), - lambda arr: dict(zip(range(len(arr)), arr)), - lambda arr: [(i, -i) for i in arr], - lambda arr: [[i, -i] for i in arr], - lambda arr: ([(i, -i) for i in arr][:-1] + [None]), - lambda arr: ([[i, -i] for i in arr][:-1] + [None])], + list_of_str, + gen_of_str, + arr_dict, + list_of_tuples, + gen_of_tuples, + list_of_lists, + list_of_tuples_with_none, + list_of_lists_with_none], [False, True]] def setup(self, data_fmt, with_index):