Skip to content

PERF: 10x speedup in Series/DataFrame construction for lists of ints #24647

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

Merged
merged 1 commit into from
Jan 6, 2019
Merged
Show file tree
Hide file tree
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
14 changes: 9 additions & 5 deletions asv_bench/benchmarks/ctors.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def list_of_lists_with_none(arr):

class SeriesConstructors(object):

param_names = ["data_fmt", "with_index"]
param_names = ["data_fmt", "with_index", "dtype"]
params = [[no_change,
list,
list_of_str,
Expand All @@ -52,15 +52,19 @@ class SeriesConstructors(object):
list_of_lists,
list_of_tuples_with_none,
list_of_lists_with_none],
[False, True]]
[False, True],
['float', 'int']]

def setup(self, data_fmt, with_index):
def setup(self, data_fmt, with_index, dtype):
N = 10**4
arr = np.random.randn(N)
if dtype == 'float':
arr = np.random.randn(N)
else:
arr = np.arange(N)
self.data = data_fmt(arr)
self.index = np.arange(N) if with_index else None

def time_series_constructor(self, data_fmt, with_index):
def time_series_constructor(self, data_fmt, with_index, dtype):
Series(self.data, index=self.index)


Expand Down
3 changes: 2 additions & 1 deletion pandas/_libs/lib.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2011,7 +2011,8 @@ def maybe_convert_objects(ndarray[object] objects, bint try_float=0,
floats[i] = <float64_t>val
complexes[i] = <double complex>val
if not seen.null_:
seen.saw_int(int(val))
val = int(val)
seen.saw_int(val)
Copy link
Member

Choose a reason for hiding this comment

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

can saw_int's signature be tightened up?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It can, but I didn't see any significant difference when changing it to cdef inline saw_int(self, int val), so took that out to keep this minimal. That call is only used in this file, and only a few times at that so it'd be fine to tighten it up.


if ((seen.uint_ and seen.sint_) or
val > oUINT64_MAX or val < oINT64_MIN):
Expand Down