diff --git a/asv_bench/benchmarks/ctors.py b/asv_bench/benchmarks/ctors.py index 198ed1c90a2e9..7c78fe7e7a177 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):