Skip to content

Commit a47ad56

Browse files
mroeschkejorisvandenbossche
authored andcommitted
CLN: ASV remove uncessary selfs and add setups (pandas-dev#18575)
1 parent 7627cca commit a47ad56

File tree

7 files changed

+37
-46
lines changed

7 files changed

+37
-46
lines changed

asv_bench/benchmarks/algorithms.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
except:
1212
pass
1313

14+
from .pandas_vb_common import setup # noqa
15+
1416

1517
class Factorize(object):
1618

@@ -21,7 +23,6 @@ class Factorize(object):
2123

2224
def setup(self, sort):
2325
N = 10**5
24-
np.random.seed(1234)
2526
self.int_idx = pd.Int64Index(np.arange(N).repeat(5))
2627
self.float_idx = pd.Float64Index(np.random.randn(N).repeat(5))
2728
self.string_idx = tm.makeStringIndex(N)
@@ -45,7 +46,6 @@ class Duplicated(object):
4546

4647
def setup(self, keep):
4748
N = 10**5
48-
np.random.seed(1234)
4949
self.int_idx = pd.Int64Index(np.arange(N).repeat(5))
5050
self.float_idx = pd.Float64Index(np.random.randn(N).repeat(5))
5151
self.string_idx = tm.makeStringIndex(N)
@@ -79,7 +79,6 @@ class Match(object):
7979
goal_time = 0.2
8080

8181
def setup(self):
82-
np.random.seed(1234)
8382
self.uniques = tm.makeStringIndex(1000).values
8483
self.all = self.uniques.repeat(10)
8584

@@ -92,7 +91,6 @@ class Hashing(object):
9291
goal_time = 0.2
9392

9493
def setup_cache(self):
95-
np.random.seed(1234)
9694
N = 10**5
9795

9896
df = pd.DataFrame(

asv_bench/benchmarks/binary_ops.py

+7-10
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
except ImportError:
77
import pandas.computation.expressions as expr
88

9+
from .pandas_vb_common import setup # noqa
10+
911

1012
class Ops(object):
1113

@@ -15,7 +17,6 @@ class Ops(object):
1517
param_names = ['use_numexpr', 'threads']
1618

1719
def setup(self, use_numexpr, threads):
18-
np.random.seed(1234)
1920
self.df = DataFrame(np.random.randn(20000, 100))
2021
self.df2 = DataFrame(np.random.randn(20000, 100))
2122

@@ -47,7 +48,6 @@ class Ops2(object):
4748

4849
def setup(self):
4950
N = 10**3
50-
np.random.seed(1234)
5151
self.df = DataFrame(np.random.randn(N, N))
5252
self.df2 = DataFrame(np.random.randn(N, N))
5353

@@ -89,14 +89,12 @@ class Timeseries(object):
8989
param_names = ['tz']
9090

9191
def setup(self, tz):
92-
self.N = 10**6
93-
self.halfway = ((self.N // 2) - 1)
94-
self.s = Series(date_range('20010101', periods=self.N, freq='T',
95-
tz=tz))
96-
self.ts = self.s[self.halfway]
92+
N = 10**6
93+
halfway = (N // 2) - 1
94+
self.s = Series(date_range('20010101', periods=N, freq='T', tz=tz))
95+
self.ts = self.s[halfway]
9796

98-
self.s2 = Series(date_range('20010101', periods=self.N, freq='s',
99-
tz=tz))
97+
self.s2 = Series(date_range('20010101', periods=N, freq='s', tz=tz))
10098

10199
def time_series_timestamp_compare(self, tz):
102100
self.s <= self.ts
@@ -131,7 +129,6 @@ class AddOverflowArray(object):
131129
goal_time = 0.2
132130

133131
def setup(self):
134-
np.random.seed(1234)
135132
N = 10**6
136133
self.arr = np.arange(N)
137134
self.arr_rev = np.arange(-N, 0)

asv_bench/benchmarks/categoricals.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
except ImportError:
1010
pass
1111

12+
from .pandas_vb_common import setup # noqa
13+
1214

1315
class Concat(object):
1416

@@ -76,7 +78,6 @@ class ValueCounts(object):
7678

7779
def setup(self, dropna):
7880
n = 5 * 10**5
79-
np.random.seed(2718281)
8081
arr = ['s%04d' % i for i in np.random.randint(0, n // 10, size=n)]
8182
self.ts = pd.Series(arr).astype('category')
8283

@@ -101,7 +102,6 @@ class SetCategories(object):
101102

102103
def setup(self):
103104
n = 5 * 10**5
104-
np.random.seed(2718281)
105105
arr = ['s%04d' % i for i in np.random.randint(0, n // 10, size=n)]
106106
self.ts = pd.Series(arr).astype('category')
107107

@@ -116,7 +116,6 @@ class Rank(object):
116116
def setup(self):
117117
N = 10**5
118118
ncats = 100
119-
np.random.seed(1234)
120119

121120
self.s_str = pd.Series(tm.makeCategoricalIndex(N, ncats)).astype(str)
122121
self.s_str_cat = self.s_str.astype('category')

asv_bench/benchmarks/ctors.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import numpy as np
22
from pandas import DataFrame, Series, Index, DatetimeIndex, Timestamp
33

4+
from .pandas_vb_common import setup # noqa
5+
46

57
class Constructors(object):
68

79
goal_time = 0.2
810

911
def setup(self):
1012
N = 10**2
11-
np.random.seed(1234)
1213
self.arr = np.random.randn(N, N)
1314
self.arr_str = np.array(['foo', 'bar', 'baz'], dtype=object)
1415

asv_bench/benchmarks/eval.py

+12-12
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
except ImportError:
66
import pandas.computation.expressions as expr
77

8+
from .pandas_vb_common import setup # noqa
9+
810

911
class Eval(object):
1012

@@ -14,7 +16,6 @@ class Eval(object):
1416
param_names = ['engine', 'threads']
1517

1618
def setup(self, engine, threads):
17-
np.random.seed(1234)
1819
self.df = pd.DataFrame(np.random.randn(20000, 100))
1920
self.df2 = pd.DataFrame(np.random.randn(20000, 100))
2021
self.df3 = pd.DataFrame(np.random.randn(20000, 100))
@@ -45,17 +46,16 @@ class Query(object):
4546
goal_time = 0.2
4647

4748
def setup(self):
48-
np.random.seed(1234)
49-
self.N = 10**6
50-
self.halfway = (self.N // 2) - 1
51-
self.index = pd.date_range('20010101', periods=self.N, freq='T')
52-
self.s = pd.Series(self.index)
53-
self.ts = self.s.iloc[self.halfway]
54-
self.df = pd.DataFrame({'a': np.random.randn(self.N), 'dates': self.s},
55-
index=self.index)
56-
self.data = np.random.randn(self.N)
57-
self.min_val = self.data.min()
58-
self.max_val = self.data.max()
49+
N = 10**6
50+
halfway = (N // 2) - 1
51+
index = pd.date_range('20010101', periods=N, freq='T')
52+
s = pd.Series(index)
53+
self.ts = s.iloc[halfway]
54+
self.df = pd.DataFrame({'a': np.random.randn(N), 'dates': s},
55+
index=index)
56+
data = np.random.randn(N)
57+
self.min_val = data.min()
58+
self.max_val = data.max()
5959

6060
def time_query_datetime_index(self):
6161
self.df.query('index < @self.ts')

asv_bench/benchmarks/frame_ctor.py

+10-15
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,23 @@
44
try:
55
from pandas.tseries import offsets
66
except:
7-
from pandas.core.datetools import *
7+
from pandas.core.datetools import * # noqa
88

9+
from .pandas_vb_common import setup # noqa
910

10-
# ----------------------------------------------------------------------
11-
# Creation from nested dict
1211

1312
class FromDicts(object):
1413

1514
goal_time = 0.2
1615

1716
def setup(self):
18-
np.random.seed(1234)
1917
N, K = 5000, 50
20-
self.index = tm.makeStringIndex(N)
21-
self.columns = tm.makeStringIndex(K)
22-
self.frame = DataFrame(np.random.randn(N, K),
23-
index=self.index,
24-
columns=self.columns)
25-
self.data = self.frame.to_dict()
18+
index = tm.makeStringIndex(N)
19+
columns = tm.makeStringIndex(K)
20+
frame = DataFrame(np.random.randn(N, K), index=index, columns=columns)
21+
self.data = frame.to_dict()
2622
self.some_dict = list(self.data.values())[0]
27-
self.dict_list = self.frame.to_dict(orient='records')
23+
self.dict_list = frame.to_dict(orient='records')
2824
self.data2 = {i: {j: float(j) for j in range(100)}
2925
for i in range(2000)}
3026

@@ -42,14 +38,13 @@ def time_frame_ctor_nested_dict_int64(self):
4238
DataFrame(self.data2)
4339

4440

45-
# from a mi-series
46-
4741
class FromSeries(object):
42+
4843
goal_time = 0.2
4944

5045
def setup(self):
51-
self.mi = MultiIndex.from_product([range(100), range(100)])
52-
self.s = Series(np.random.randn(10000), index=self.mi)
46+
mi = MultiIndex.from_product([range(100), range(100)])
47+
self.s = Series(np.random.randn(10000), index=mi)
5348

5449
def time_frame_from_mi_series(self):
5550
DataFrame(self.s)

asv_bench/benchmarks/frame_methods.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
import pandas.util.testing as tm
44
from pandas import (DataFrame, Series, MultiIndex, date_range, period_range,
55
isnull, NaT)
6-
from .pandas_vb_common import setup
6+
7+
from .pandas_vb_common import setup # noqa
78

89

910
class GetNumericData(object):

0 commit comments

Comments
 (0)