Skip to content

Commit 4a00fcc

Browse files
authored
BENCH: Remove unnecessary random seeds (#41889)
1 parent 6f953a8 commit 4a00fcc

File tree

6 files changed

+4
-14
lines changed

6 files changed

+4
-14
lines changed

asv_bench/benchmarks/algos/isin.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@ def setup(self, dtype):
5050

5151
elif dtype in ["category[object]", "category[int]"]:
5252
# Note: sizes are different in this case than others
53-
np.random.seed(1234)
54-
5553
n = 5 * 10 ** 5
5654
sample_size = 100
5755

@@ -99,7 +97,6 @@ class IsinAlmostFullWithRandomInt:
9997
def setup(self, dtype, exponent, title):
10098
M = 3 * 2 ** (exponent - 2)
10199
# 0.77-the maximal share of occupied buckets
102-
np.random.seed(42)
103100
self.series = Series(np.random.randint(0, M, M)).astype(dtype)
104101

105102
values = np.random.randint(0, M, M).astype(dtype)
@@ -132,7 +129,6 @@ class IsinWithRandomFloat:
132129
param_names = ["dtype", "size", "title"]
133130

134131
def setup(self, dtype, size, title):
135-
np.random.seed(42)
136132
self.values = np.random.rand(size)
137133
self.series = Series(self.values).astype(dtype)
138134
np.random.shuffle(self.values)
@@ -179,7 +175,6 @@ class IsinWithArange:
179175

180176
def setup(self, dtype, M, offset_factor):
181177
offset = int(M * offset_factor)
182-
np.random.seed(42)
183178
tmp = Series(np.random.randint(offset, M + offset, 10 ** 6))
184179
self.series = tmp.astype(dtype)
185180
self.values = np.arange(M).astype(dtype)
@@ -290,10 +285,8 @@ def setup(self, dtype, MaxNumber, series_type):
290285
raise NotImplementedError
291286

292287
if series_type == "random_hits":
293-
np.random.seed(42)
294288
array = np.random.randint(0, MaxNumber, N)
295289
if series_type == "random_misses":
296-
np.random.seed(42)
297290
array = np.random.randint(0, MaxNumber, N) + MaxNumber
298291
if series_type == "monotone_hits":
299292
array = np.repeat(np.arange(MaxNumber), N // MaxNumber)
@@ -322,7 +315,6 @@ def setup(self, dtype, series_type):
322315
raise NotImplementedError
323316

324317
if series_type == "random":
325-
np.random.seed(42)
326318
vals = np.random.randint(0, 10 * N, N)
327319
if series_type == "monotone":
328320
vals = np.arange(N)

asv_bench/benchmarks/frame_ctor.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ class FromDictwithTimestamp:
6767

6868
def setup(self, offset):
6969
N = 10 ** 3
70-
np.random.seed(1234)
7170
idx = date_range(Timestamp("1/1/1900"), freq=offset, periods=N)
7271
df = DataFrame(np.random.randn(N, 10), index=idx)
7372
self.d = df.to_dict()

asv_bench/benchmarks/hash_functions.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ class NumericSeriesIndexingShuffled:
6767

6868
def setup(self, index, N):
6969
vals = np.array(list(range(55)) + [54] + list(range(55, N - 1)))
70-
np.random.seed(42)
7170
np.random.shuffle(vals)
7271
indices = index(vals)
7372
self.data = pd.Series(np.arange(N), index=indices)

asv_bench/benchmarks/indexing.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -368,17 +368,14 @@ def setup(self):
368368
self.df = DataFrame(index=range(self.N))
369369

370370
def time_insert(self):
371-
np.random.seed(1234)
372371
for i in range(100):
373372
self.df.insert(0, i, np.random.randn(self.N), allow_duplicates=True)
374373

375374
def time_assign_with_setitem(self):
376-
np.random.seed(1234)
377375
for i in range(100):
378376
self.df[i] = np.random.randn(self.N)
379377

380378
def time_assign_list_like_with_setitem(self):
381-
np.random.seed(1234)
382379
self.df[list(range(100))] = np.random.randn(self.N, 100)
383380

384381
def time_assign_list_of_columns_concat(self):

asv_bench/benchmarks/series_methods.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,6 @@ class Mode:
145145
param_names = ["N", "dtype"]
146146

147147
def setup(self, N, dtype):
148-
np.random.seed(42)
149148
self.s = Series(np.random.randint(0, N, size=10 * N)).astype(dtype)
150149

151150
def time_mode(self, N, dtype):

ci/code_checks.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ if [[ -z "$CHECK" || "$CHECK" == "patterns" ]]; then
7777
invgrep -R --include="*.rst" -E "[a-zA-Z0-9]\`\`?[a-zA-Z0-9]" doc/source/
7878
RET=$(($RET + $?)) ; echo $MSG "DONE"
7979

80+
MSG='Check for unnecessary random seeds in asv benchmarks' ; echo $MSG
81+
invgrep -R --exclude pandas_vb_common.py -E 'np.random.seed' asv_bench/benchmarks/
82+
RET=$(($RET + $?)) ; echo $MSG "DONE"
83+
8084
fi
8185

8286
### CODE ###

0 commit comments

Comments
 (0)