Skip to content

Commit dba6fb4

Browse files
committed
TST: asv benchmarks for Series constructors
1 parent 35ffa9e commit dba6fb4

File tree

2 files changed

+36
-7
lines changed

2 files changed

+36
-7
lines changed

asv_bench/benchmarks/ctors.py

+24-7
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,30 @@
44
from .pandas_vb_common import setup # noqa
55

66

7-
class Constructors(object):
7+
class SeriesConstructors(object):
8+
9+
goal_time = 0.2
10+
11+
param_names = ["data_fmt", "with_index"]
12+
params = [[lambda x: x,
13+
list,
14+
lambda arr: dict(zip(range(len(arr)), arr)),
15+
lambda arr: [[i, -i] for i in arr],
16+
lambda arr: ([[i, -i] for i in arr][:-1] + [None])],
17+
[False, True]]
18+
19+
def setup(self, data_fmt, with_index):
20+
N = 10**2
21+
np.random.seed(1234)
22+
arr = np.random.randn(N)
23+
self.data = data_fmt(arr)
24+
self.index = np.arange(N) if with_index else None
25+
26+
def time_series_constructor(self, data_fmt, with_index):
27+
Series(self.data, index=self.index)
28+
29+
30+
class SeriesDtypesConstructors(object):
831

932
goal_time = 0.2
1033

@@ -19,12 +42,6 @@ def setup(self):
1942
self.s = Series([Timestamp('20110101'), Timestamp('20120101'),
2043
Timestamp('20130101')] * N * 10)
2144

22-
def time_frame_from_ndarray(self):
23-
DataFrame(self.arr)
24-
25-
def time_series_from_ndarray(self):
26-
Series(self.data, index=self.index)
27-
2845
def time_index_from_array_string(self):
2946
Index(self.arr_str)
3047

asv_bench/benchmarks/frame_ctor.py

+12
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,15 @@ def setup(self, nrows):
8181
def time_frame_from_records_generator(self, nrows):
8282
# issue-6700
8383
self.df = DataFrame.from_records(self.gen, nrows=nrows)
84+
85+
86+
class FromNDArray(object):
87+
88+
goal_time = 0.2
89+
90+
def setup(self):
91+
N = 100000
92+
self.data = np.random.randn(N)
93+
94+
def time_frame_from_ndarray(self):
95+
self.df = DataFrame(self.data)

0 commit comments

Comments
 (0)