@@ -1064,25 +1064,33 @@ def test_vector_resize(self):
1064
1064
# Test for memory errors after internal vector
1065
1065
# reallocations (pull request #7157)
1066
1066
1067
- def _test_vector_resize (htable , uniques , dtype , nvals ):
1067
+ def _test_vector_resize (htable , uniques , dtype , nvals , tmp_changes ):
1068
1068
vals = np .array (np .random .randn (1000 ), dtype = dtype )
1069
1069
# get_labels appends to the vector
1070
1070
htable .get_labels (vals [:nvals ], uniques , 0 , - 1 )
1071
1071
# to_array resizes the vector
1072
- uniques .to_array (refcheck = False )
1072
+ tmp = uniques .to_array (refcheck = False )
1073
+ oldshape = tmp .shape
1073
1074
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
1074
1082
1075
1083
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 )]
1081
1089
1082
- for (tbl , vect , dtype ) in test_cases :
1090
+ for (tbl , vect , dtype , tmp_changes ) in test_cases :
1083
1091
# 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 )
1086
1094
1087
1095
1088
1096
def test_quantile ():
0 commit comments