@@ -164,14 +164,18 @@ def test_get_state(self, table_type, dtype):
164
164
assert "upper_bound" in state
165
165
166
166
def test_no_reallocation (self , table_type , dtype ):
167
- N = 110
168
- keys = np .arange (N ).astype (dtype )
169
- table = table_type (N )
170
- n_buckets_start = table .get_state ()["n_buckets" ]
171
- table .map_locations (keys )
172
- n_buckets_end = table .get_state ()["n_buckets" ]
173
- # orgininal number of buckets was enough:
174
- assert n_buckets_start == n_buckets_end
167
+ for N in range (1 , 110 ):
168
+ keys = np .arange (N ).astype (dtype )
169
+ preallocated_table = table_type (N )
170
+ n_buckets_start = preallocated_table .get_state ()["n_buckets" ]
171
+ preallocated_table .map_locations (keys )
172
+ n_buckets_end = preallocated_table .get_state ()["n_buckets" ]
173
+ # orgininal number of buckets was enough:
174
+ assert n_buckets_start == n_buckets_end
175
+ # check with clean table (not too much preallocated)
176
+ clean_table = table_type ()
177
+ clean_table .map_locations (keys )
178
+ assert n_buckets_start == clean_table .get_state ()["n_buckets" ]
175
179
176
180
177
181
def test_get_labels_groupby_for_Int64 (writable ):
@@ -209,14 +213,18 @@ def test_tracemalloc_for_empty_StringHashTable():
209
213
210
214
211
215
def test_no_reallocation_StringHashTable ():
212
- N = 110
213
- keys = np .arange (N ).astype (np .compat .unicode ).astype (np .object_ )
214
- table = ht .StringHashTable (N )
215
- n_buckets_start = table .get_state ()["n_buckets" ]
216
- table .map_locations (keys )
217
- n_buckets_end = table .get_state ()["n_buckets" ]
218
- # orgininal number of buckets was enough:
219
- assert n_buckets_start == n_buckets_end
216
+ for N in range (1 , 110 ):
217
+ keys = np .arange (N ).astype (np .compat .unicode ).astype (np .object_ )
218
+ preallocated_table = ht .StringHashTable (N )
219
+ n_buckets_start = preallocated_table .get_state ()["n_buckets" ]
220
+ preallocated_table .map_locations (keys )
221
+ n_buckets_end = preallocated_table .get_state ()["n_buckets" ]
222
+ # orgininal number of buckets was enough:
223
+ assert n_buckets_start == n_buckets_end
224
+ # check with clean table (not too much preallocated)
225
+ clean_table = ht .StringHashTable ()
226
+ clean_table .map_locations (keys )
227
+ assert n_buckets_start == clean_table .get_state ()["n_buckets" ]
220
228
221
229
222
230
@pytest .mark .parametrize (
0 commit comments