forked from pandas-dev/pandas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhash_functions.py
173 lines (133 loc) · 4.36 KB
/
hash_functions.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
import numpy as np
import pandas as pd
class IsinAlmostFullWithRandomInt:
params = [
[np.float64, np.int64, np.uint64, np.object],
range(10, 21),
]
param_names = ["dtype", "exponent"]
def setup(self, dtype, exponent):
M = 3 * 2 ** (exponent - 2)
# 0.77-the maximal share of occupied buckets
np.random.seed(42)
self.s = pd.Series(np.random.randint(0, M, M)).astype(dtype)
self.values = np.random.randint(0, M, M).astype(dtype)
self.values_outside = self.values + M
def time_isin(self, dtype, exponent):
self.s.isin(self.values)
def time_isin_outside(self, dtype, exponent):
self.s.isin(self.values_outside)
class UniqueForLargePyObjectInts:
def setup(self):
lst = [x << 32 for x in range(5000)]
self.arr = np.array(lst, dtype=np.object_)
def time_unique(self):
pd.unique(self.arr)
class IsinWithRandomFloat:
params = [
[np.float64, np.object],
[
1_300,
2_000,
7_000,
8_000,
70_000,
80_000,
750_000,
900_000,
],
]
param_names = ["dtype", "M"]
def setup(self, dtype, M):
np.random.seed(42)
self.values = np.random.rand(M)
self.s = pd.Series(self.values).astype(dtype)
np.random.shuffle(self.values)
self.values_outside = self.values + 0.1
def time_isin(self, dtype, M):
self.s.isin(self.values)
def time_isin_outside(self, dtype, M):
self.s.isin(self.values_outside)
class IsinWithArangeSorted:
params = [
[np.float64, np.int64, np.uint64, np.object],
[
1_000,
2_000,
8_000,
100_000,
1_000_000,
],
]
param_names = ["dtype", "M"]
def setup(self, dtype, M):
self.s = pd.Series(np.arange(M)).astype(dtype)
self.values = np.arange(M).astype(dtype)
def time_isin(self, dtype, M):
self.s.isin(self.values)
class IsinWithArange:
params = [
[np.float64, np.int64, np.uint64, np.object],
[
1_000,
2_000,
8_000,
],
[-2, 0, 2],
]
param_names = ["dtype", "M", "offset_factor"]
def setup(self, dtype, M, offset_factor):
offset = int(M * offset_factor)
np.random.seed(42)
tmp = pd.Series(np.random.randint(offset, M + offset, 10 ** 6))
self.s = tmp.astype(dtype)
self.values = np.arange(M).astype(dtype)
def time_isin(self, dtype, M, offset_factor):
self.s.isin(self.values)
class Float64GroupIndex:
# GH28303
def setup(self):
self.df = pd.date_range(
start="1/1/2018", end="1/2/2018", periods=10 ** 6
).to_frame()
self.group_index = np.round(self.df.index.astype(int) / 10 ** 9)
def time_groupby(self):
self.df.groupby(self.group_index).last()
class UniqueAndFactorizeArange:
params = range(4, 16)
param_names = ["exponent"]
def setup(self, exponent):
a = np.arange(10 ** 4, dtype="float64")
self.a2 = (a + 10 ** exponent).repeat(100)
def time_factorize(self, exponent):
pd.factorize(self.a2)
def time_unique(self, exponent):
pd.unique(self.a2)
class NumericSeriesIndexing:
params = [
(pd.Int64Index, pd.UInt64Index, pd.Float64Index),
(10 ** 4, 10 ** 5, 5 * 10 ** 5, 10 ** 6, 5 * 10 ** 6),
]
param_names = ["index_dtype", "N"]
def setup(self, index, N):
vals = np.array(list(range(55)) + [54] + list(range(55, N - 1)))
indices = index(vals)
self.data = pd.Series(np.arange(N), index=indices)
def time_loc_slice(self, index, N):
# trigger building of mapping
self.data.loc[:800]
class NumericSeriesIndexingShuffled:
params = [
(pd.Int64Index, pd.UInt64Index, pd.Float64Index),
(10 ** 4, 10 ** 5, 5 * 10 ** 5, 10 ** 6, 5 * 10 ** 6),
]
param_names = ["index_dtype", "N"]
def setup(self, index, N):
vals = np.array(list(range(55)) + [54] + list(range(55, N - 1)))
np.random.seed(42)
np.random.shuffle(vals)
indices = index(vals)
self.data = pd.Series(np.arange(N), index=indices)
def time_loc_slice(self, index, N):
# trigger building of mapping
self.data.loc[:800]