Skip to content

Commit f349d07

Browse files
qwhelanPingviinituutti
authored andcommitted
CLN: replace lambdas with named functions so they are labeled in asv (pandas-dev#24629)
1 parent d65102e commit f349d07

File tree

1 file changed

+45
-7
lines changed

1 file changed

+45
-7
lines changed

asv_bench/benchmarks/ctors.py

+45-7
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,55 @@
33
from pandas import Series, Index, DatetimeIndex, Timestamp, MultiIndex
44

55

6+
def no_change(arr):
7+
return arr
8+
9+
10+
def list_of_str(arr):
11+
return list(arr.astype(str))
12+
13+
14+
def gen_of_str(arr):
15+
return (x for x in arr.astype(str))
16+
17+
18+
def arr_dict(arr):
19+
return dict(zip(range(len(arr)), arr))
20+
21+
22+
def list_of_tuples(arr):
23+
return [(i, -i) for i in arr]
24+
25+
26+
def gen_of_tuples(arr):
27+
return ((i, -i) for i in arr)
28+
29+
30+
def list_of_lists(arr):
31+
return [[i, -i] for i in arr]
32+
33+
34+
def list_of_tuples_with_none(arr):
35+
return [(i, -i) for i in arr][:-1] + [None]
36+
37+
38+
def list_of_lists_with_none(arr):
39+
return [[i, -i] for i in arr][:-1] + [None]
40+
41+
642
class SeriesConstructors(object):
743

844
param_names = ["data_fmt", "with_index"]
9-
params = [[lambda x: x,
45+
params = [[no_change,
1046
list,
11-
lambda arr: list(arr.astype(str)),
12-
lambda arr: dict(zip(range(len(arr)), arr)),
13-
lambda arr: [(i, -i) for i in arr],
14-
lambda arr: [[i, -i] for i in arr],
15-
lambda arr: ([(i, -i) for i in arr][:-1] + [None]),
16-
lambda arr: ([[i, -i] for i in arr][:-1] + [None])],
47+
list_of_str,
48+
gen_of_str,
49+
arr_dict,
50+
list_of_tuples,
51+
gen_of_tuples,
52+
list_of_lists,
53+
list_of_tuples_with_none,
54+
list_of_lists_with_none],
1755
[False, True]]
1856

1957
def setup(self, data_fmt, with_index):

0 commit comments

Comments
 (0)