forked from pandas-dev/pandas
-
Notifications
You must be signed in to change notification settings - Fork 2
/
index_object.py
221 lines (153 loc) · 5.75 KB
/
index_object.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
from .pandas_vb_common import *
class SetOperations(object):
goal_time = 0.2
def setup(self):
self.rng = date_range('1/1/2000', periods=10000, freq='T')
self.rng2 = self.rng[:(-1)]
# object index with datetime values
if (self.rng.dtype == object):
self.idx_rng = self.rng.view(Index)
else:
self.idx_rng = self.rng.asobject
self.idx_rng2 = self.idx_rng[:(-1)]
# other datetime
N = 100000
A = N - 20000
B = N + 20000
self.dtidx1 = DatetimeIndex(range(N))
self.dtidx2 = DatetimeIndex(range(A, B))
self.dtidx3 = DatetimeIndex(range(N, B))
# integer
self.N = 1000000
self.options = np.arange(self.N)
self.left = Index(
self.options.take(np.random.permutation(self.N)[:(self.N // 2)]))
self.right = Index(
self.options.take(np.random.permutation(self.N)[:(self.N // 2)]))
# strings
N = 10000
strs = tm.rands_array(10, N)
self.leftstr = Index(strs[:N * 2 // 3])
self.rightstr = Index(strs[N // 3:])
def time_datetime_intersection(self):
self.rng.intersection(self.rng2)
def time_datetime_union(self):
self.rng.union(self.rng2)
def time_datetime_difference(self):
self.dtidx1.difference(self.dtidx2)
def time_datetime_difference_disjoint(self):
self.dtidx1.difference(self.dtidx3)
def time_datetime_symmetric_difference(self):
self.dtidx1.symmetric_difference(self.dtidx2)
def time_index_datetime_intersection(self):
self.idx_rng.intersection(self.idx_rng2)
def time_index_datetime_union(self):
self.idx_rng.union(self.idx_rng2)
def time_int64_intersection(self):
self.left.intersection(self.right)
def time_int64_union(self):
self.left.union(self.right)
def time_int64_difference(self):
self.left.difference(self.right)
def time_int64_symmetric_difference(self):
self.left.symmetric_difference(self.right)
def time_str_difference(self):
self.leftstr.difference(self.rightstr)
def time_str_symmetric_difference(self):
self.leftstr.symmetric_difference(self.rightstr)
class Datetime(object):
goal_time = 0.2
def setup(self):
self.dr = pd.date_range('20000101', freq='D', periods=10000)
def time_is_dates_only(self):
self.dr._is_dates_only
class Float64(object):
goal_time = 0.2
def setup(self):
self.idx = tm.makeFloatIndex(1000000)
self.mask = ((np.arange(self.idx.size) % 3) == 0)
self.series_mask = Series(self.mask)
self.baseidx = np.arange(1000000.0)
def time_boolean_indexer(self):
self.idx[self.mask]
def time_boolean_series_indexer(self):
self.idx[self.series_mask]
def time_construct(self):
Index(self.baseidx)
def time_div(self):
(self.idx / 2)
def time_get(self):
self.idx[1]
def time_mul(self):
(self.idx * 2)
def time_slice_indexer_basic(self):
self.idx[:(-1)]
def time_slice_indexer_even(self):
self.idx[::2]
class StringIndex(object):
goal_time = 0.2
def setup(self):
self.idx = tm.makeStringIndex(1000000)
self.mask = ((np.arange(1000000) % 3) == 0)
self.series_mask = Series(self.mask)
def time_boolean_indexer(self):
self.idx[self.mask]
def time_boolean_series_indexer(self):
self.idx[self.series_mask]
def time_slice_indexer_basic(self):
self.idx[:(-1)]
def time_slice_indexer_even(self):
self.idx[::2]
class Multi1(object):
goal_time = 0.2
def setup(self):
(n, k) = (200, 5000)
self.levels = [np.arange(n), tm.makeStringIndex(n).values, (1000 + np.arange(n))]
self.labels = [np.random.choice(n, (k * n)) for lev in self.levels]
self.mi = MultiIndex(levels=self.levels, labels=self.labels)
self.iterables = [tm.makeStringIndex(10000), range(20)]
def time_duplicated(self):
self.mi.duplicated()
def time_from_product(self):
MultiIndex.from_product(self.iterables)
class Multi2(object):
goal_time = 0.2
def setup(self):
self.n = ((((3 * 5) * 7) * 11) * (1 << 10))
(low, high) = (((-1) << 12), (1 << 12))
self.f = (lambda k: np.repeat(np.random.randint(low, high, (self.n // k)), k))
self.i = np.random.permutation(self.n)
self.mi = MultiIndex.from_arrays([self.f(11), self.f(7), self.f(5), self.f(3), self.f(1)])[self.i]
self.a = np.repeat(np.arange(100), 1000)
self.b = np.tile(np.arange(1000), 100)
self.midx2 = MultiIndex.from_arrays([self.a, self.b])
self.midx2 = self.midx2.take(np.random.permutation(np.arange(100000)))
def time_sortlevel_int64(self):
self.mi.sortlevel()
def time_sortlevel_zero(self):
self.midx2.sortlevel(0)
def time_sortlevel_one(self):
self.midx2.sortlevel(1)
class Multi3(object):
goal_time = 0.2
def setup(self):
self.level1 = range(1000)
self.level2 = date_range(start='1/1/2012', periods=100)
self.mi = MultiIndex.from_product([self.level1, self.level2])
def time_datetime_level_values_full(self):
self.mi.copy().values
def time_datetime_level_values_sliced(self):
self.mi[:10].values
class Range(object):
goal_time = 0.2
def setup(self):
self.idx_inc = RangeIndex(start=0, stop=10**7, step=3)
self.idx_dec = RangeIndex(start=10**7, stop=-1, step=-3)
def time_max(self):
self.idx_inc.max()
def time_max_trivial(self):
self.idx_dec.max()
def time_min(self):
self.idx_dec.min()
def time_min_trivial(self):
self.idx_inc.min()