Skip to content

Commit

Permalink
CLN: replace lambdas with named functions so they are labeled in asv (p…
Browse files Browse the repository at this point in the history
  • Loading branch information
qwhelan authored and Pingviinituutti committed Feb 28, 2019
1 parent 614e3af commit f5d2ad9
Showing 1 changed file with 45 additions and 7 deletions.
52 changes: 45 additions & 7 deletions asv_bench/benchmarks/ctors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit f5d2ad9

Please sign in to comment.