Skip to content

Commit 9aaf521

Browse files
committed
TST: show how refcheck semantics leak to user space
1 parent 4acc4cd commit 9aaf521

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

pandas/tests/test_algos.py

+18-10
Original file line numberDiff line numberDiff line change
@@ -1064,25 +1064,33 @@ def test_vector_resize(self):
10641064
# Test for memory errors after internal vector
10651065
# reallocations (pull request #7157)
10661066

1067-
def _test_vector_resize(htable, uniques, dtype, nvals):
1067+
def _test_vector_resize(htable, uniques, dtype, nvals, tmp_changes):
10681068
vals = np.array(np.random.randn(1000), dtype=dtype)
10691069
# get_labels appends to the vector
10701070
htable.get_labels(vals[:nvals], uniques, 0, -1)
10711071
# to_array resizes the vector
1072-
uniques.to_array(refcheck=False)
1072+
tmp = uniques.to_array(refcheck=False)
1073+
oldshape = tmp.shape
10731074
htable.get_labels(vals, uniques, 0, -1, refcheck=False)
1075+
with pytest.raises(ValueError):
1076+
# cannot resize, tmp is holding a reference
1077+
tmp2 = uniques.to_array() #refcheck=True is default value
1078+
# DANGEROUS - could change tmp
1079+
uniques.to_array(refcheck=False)
1080+
if tmp_changes:
1081+
assert oldshape != tmp.shape
10741082

10751083
test_cases = [
1076-
(hashtable.PyObjectHashTable, hashtable.ObjectVector, 'object'),
1077-
(hashtable.StringHashTable, hashtable.ObjectVector, 'object'),
1078-
(hashtable.Float64HashTable, hashtable.Float64Vector, 'float64'),
1079-
(hashtable.Int64HashTable, hashtable.Int64Vector, 'int64'),
1080-
(hashtable.UInt64HashTable, hashtable.UInt64Vector, 'uint64')]
1084+
(hashtable.PyObjectHashTable, hashtable.ObjectVector, 'object', True),
1085+
(hashtable.StringHashTable, hashtable.ObjectVector, 'object', False),
1086+
(hashtable.Float64HashTable, hashtable.Float64Vector, 'float64', True),
1087+
(hashtable.Int64HashTable, hashtable.Int64Vector, 'int64', True),
1088+
(hashtable.UInt64HashTable, hashtable.UInt64Vector, 'uint64', True)]
10811089

1082-
for (tbl, vect, dtype) in test_cases:
1090+
for (tbl, vect, dtype, tmp_changes) in test_cases:
10831091
# resizing to empty is a special case
1084-
_test_vector_resize(tbl(), vect(), dtype, 0)
1085-
_test_vector_resize(tbl(), vect(), dtype, 10)
1092+
_test_vector_resize(tbl(), vect(), dtype, 0, tmp_changes)
1093+
_test_vector_resize(tbl(), vect(), dtype, 10, tmp_changes)
10861094

10871095

10881096
def test_quantile():

0 commit comments

Comments
 (0)