@@ -75,33 +75,33 @@ def test_get_set_contains_len(self, table_type, dtype):
75
75
table .get_item (index + 2 )
76
76
assert str (index + 2 ) in str (excinfo .value )
77
77
78
- def test_map (self , table_type , dtype ):
78
+ def test_map (self , table_type , dtype , writable ):
79
79
# PyObjectHashTable has no map-method
80
80
if table_type != ht .PyObjectHashTable :
81
81
N = 77
82
82
table = table_type ()
83
83
keys = np .arange (N ).astype (dtype )
84
84
vals = np .arange (N ).astype (np .int64 ) + N
85
- keys .flags .writeable = False
86
- vals .flags .writeable = False
85
+ keys .flags .writeable = writable
86
+ vals .flags .writeable = writable
87
87
table .map (keys , vals )
88
88
for i in range (N ):
89
89
assert table .get_item (keys [i ]) == i + N
90
90
91
- def test_map_locations (self , table_type , dtype ):
91
+ def test_map_locations (self , table_type , dtype , writable ):
92
92
N = 8
93
93
table = table_type ()
94
94
keys = (np .arange (N ) + N ).astype (dtype )
95
- keys .flags .writeable = False
95
+ keys .flags .writeable = writable
96
96
table .map_locations (keys )
97
97
for i in range (N ):
98
98
assert table .get_item (keys [i ]) == i
99
99
100
- def test_lookup (self , table_type , dtype ):
100
+ def test_lookup (self , table_type , dtype , writable ):
101
101
N = 3
102
102
table = table_type ()
103
103
keys = (np .arange (N ) + N ).astype (dtype )
104
- keys .flags .writeable = False
104
+ keys .flags .writeable = writable
105
105
table .map_locations (keys )
106
106
result = table .lookup (keys )
107
107
expected = np .arange (N )
@@ -119,15 +119,15 @@ def test_lookup_wrong(self, table_type, dtype):
119
119
result = table .lookup (wrong_keys )
120
120
assert np .all (result == - 1 )
121
121
122
- def test_unique (self , table_type , dtype ):
122
+ def test_unique (self , table_type , dtype , writable ):
123
123
if dtype in (np .int8 , np .uint8 ):
124
124
N = 88
125
125
else :
126
126
N = 1000
127
127
table = table_type ()
128
128
expected = (np .arange (N ) + N ).astype (dtype )
129
129
keys = np .repeat (expected , 5 )
130
- keys .flags .writeable = False
130
+ keys .flags .writeable = writable
131
131
unique = table .unique (keys )
132
132
tm .assert_numpy_array_equal (unique , expected )
133
133
@@ -156,9 +156,10 @@ def test_tracemalloc_for_empty(self, table_type, dtype):
156
156
assert get_allocated_khash_memory () == 0
157
157
158
158
159
- def test_get_labels_groupby_for_Int64 ():
159
+ def test_get_labels_groupby_for_Int64 (writable ):
160
160
table = ht .Int64HashTable ()
161
161
vals = np .array ([1 , 2 , - 1 , 2 , 1 , - 1 ], dtype = np .int64 )
162
+ vals .flags .writeable = writable
162
163
arr , unique = table .get_labels_groupby (vals )
163
164
expected_arr = np .array ([0 , 1 , - 1 , 1 , 0 , - 1 ], dtype = np .int64 )
164
165
expected_unique = np .array ([1 , 2 ], dtype = np .int64 )
@@ -262,33 +263,33 @@ def get_ht_function(fun_name, type_suffix):
262
263
],
263
264
)
264
265
class TestHelpFunctions :
265
- def test_value_count (self , dtype , type_suffix ):
266
+ def test_value_count (self , dtype , type_suffix , writable ):
266
267
N = 43
267
268
value_count = get_ht_function ("value_count" , type_suffix )
268
269
expected = (np .arange (N ) + N ).astype (dtype )
269
270
values = np .repeat (expected , 5 )
270
- values .flags .writeable = False
271
+ values .flags .writeable = writable
271
272
keys , counts = value_count (values , False )
272
273
tm .assert_numpy_array_equal (np .sort (keys ), expected )
273
274
assert np .all (counts == 5 )
274
275
275
- def test_duplicated_first (self , dtype , type_suffix ):
276
+ def test_duplicated_first (self , dtype , type_suffix , writable ):
276
277
N = 100
277
278
duplicated = get_ht_function ("duplicated" , type_suffix )
278
279
values = np .repeat (np .arange (N ).astype (dtype ), 5 )
279
- values .flags .writeable = False
280
+ values .flags .writeable = writable
280
281
result = duplicated (values )
281
282
expected = np .ones_like (values , dtype = np .bool_ )
282
283
expected [::5 ] = False
283
284
tm .assert_numpy_array_equal (result , expected )
284
285
285
- def test_ismember_yes (self , dtype , type_suffix ):
286
+ def test_ismember_yes (self , dtype , type_suffix , writable ):
286
287
N = 127
287
288
ismember = get_ht_function ("ismember" , type_suffix )
288
289
arr = np .arange (N ).astype (dtype )
289
290
values = np .arange (N ).astype (dtype )
290
- arr .flags .writeable = False
291
- values .flags .writeable = False
291
+ arr .flags .writeable = writable
292
+ values .flags .writeable = writable
292
293
result = ismember (arr , values )
293
294
expected = np .ones_like (values , dtype = np .bool_ )
294
295
tm .assert_numpy_array_equal (result , expected )
@@ -302,15 +303,15 @@ def test_ismember_no(self, dtype, type_suffix):
302
303
expected = np .zeros_like (values , dtype = np .bool_ )
303
304
tm .assert_numpy_array_equal (result , expected )
304
305
305
- def test_mode (self , dtype , type_suffix ):
306
+ def test_mode (self , dtype , type_suffix , writable ):
306
307
if dtype in (np .int8 , np .uint8 ):
307
308
N = 53
308
309
else :
309
310
N = 11111
310
311
mode = get_ht_function ("mode" , type_suffix )
311
312
values = np .repeat (np .arange (N ).astype (dtype ), 5 )
312
313
values [0 ] = 42
313
- values .flags .writeable = False
314
+ values .flags .writeable = writable
314
315
result = mode (values , False )
315
316
assert result == 42
316
317
0 commit comments