Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLN: replace lambdas with named functions so they are labeled in asv #24629

Merged
merged 1 commit into from
Jan 5, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Naming nit but this is a generator expression not a list, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems the [] forces it into a list, making the outer parens a simple grouping. I'll remove the parens and add generator versions for clarity.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done - generators don't support +, so didn't add them for this particular case

return [(i, -i) for i in arr][:-1] + [None]


def list_of_lists_with_none(arr):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

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